aspose file tools*
The moose likes Beginning Java and the fly likes Insert empty field CDATA into an XML file using JDOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Insert empty field CDATA into an XML file using JDOM" Watch "Insert empty field CDATA into an XML file using JDOM" New topic
Author

Insert empty field CDATA into an XML file using JDOM

Nicola Ace
Greenhorn

Joined: Sep 27, 2010
Posts: 8
I'm trying to insert a CDATA field in a xml file using JDOM.
The problem is that the empty field is shown in the xml file like
</content>
and not like
<content></content>

It happens when the field value is like="" (then i get </content>)
If field value is "something" the <content>something</content> is correctly shown

The code i'm using is:
Element content = new Element("content");
CDATA cContenuto = new CDATA(value);
content.addContent(cContenuto);
container.addContent(content);

Someone can help me please?
tanx a lot for the answers!!

James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

Since both forms represent valid XML there should be no problem with either <content/> or <content></content> . Any parser/process that is complaining about <content/> is not XML compliant and a bug report should be raised against it.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Nicola Ace
Greenhorn

Joined: Sep 27, 2010
Posts: 8
You have been very kind, tanx for the answer.
I have tryed to validate the xml file and is correct as you said.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
It's "thanks", please, not "tanx".
Nicola Ace
Greenhorn

Joined: Sep 27, 2010
Posts: 8
My apologize.
English is not my motherlanguage.

I was at work and i was tiping as soon as i could.
This is why i used the "contract" form of thanks.

I did not want to offend anyone.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39869
    
  28
Apologies accepted.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Insert empty field CDATA into an XML file using JDOM