• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help needed on "Expand empty XML node"

 
Mamatha Kv
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to output xml node like below

<tag></tag>

instead of

<tag/>

Currently Iam doing this with DOM parser using java

Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.STANDALONE, "yes");
DOMSource domSource = new DOMSource((Node) doc);
StreamResult result = new StreamResult(file);

transformer.transform(domSource, result);

Please help... .
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why? They're semantically equivalent. All standard libraries will likely use the short form.
 
Mamatha Kv
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I agree they are semantically equivalent.
But in our case, the input xml files given by the clients for translations. We translate the node content and write back the xml file using DOM. In this process the empty nodes are replaced as <tag/>.

So when the clients view the xmls they see the difference, the way these tags are written back.

Is there way we can override this property to expand the empty nodes/tag.
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mamatha Kv wrote:

So when the clients view the xmls they see the difference, the way these tags are written back.


Since they are semantically equal, there's shouldn't be a problem if the client sees them rendered in a different way. This discussion is similar to what was discussed sometime back here
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your client simple does not understand that the two forms are equivalent, you could always write your own serializer.

Bill
 
Paul Clapham
Sheriff
Posts: 21117
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nah... all it should take is saying to the client "That's an empty element too. It works exactly the same as the empty element you typed in. There's no difference, nothing to worry about."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic