aspose file tools*
The moose likes XML and Related Technologies and the fly likes Help needed on Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help needed on "Expand empty XML node"" Watch "Help needed on "Expand empty XML node"" New topic
Author

Help needed on "Expand empty XML node"

Mamatha Kv
Greenhorn

Joined: Apr 01, 2010
Posts: 5
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
Marshal

Joined: Mar 22, 2005
Posts: 42624
    
  65
Why? They're semantically equivalent. All standard libraries will likely use the short form.


Ping & DNS - my free Android networking tools app
Mamatha Kv
Greenhorn

Joined: Apr 01, 2010
Posts: 5

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

Joined: Jul 20, 2005
Posts: 10266
    
168

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

[My Blog] [JavaRanch Journal]
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12823
    
    5
If your client simple does not understand that the two forms are equivalent, you could always write your own serializer.

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18907
    
    8

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."
 
Consider Paul's rocket mass heater.
 
subject: Help needed on "Expand empty XML node"