permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Generating xml by using Jdom,need to remove DOCTYPE and root element 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 "Generating xml by using Jdom,need to remove DOCTYPE and root element" Watch "Generating xml by using Jdom,need to remove DOCTYPE and root element" New topic
Author

Generating xml by using Jdom,need to remove DOCTYPE and root element

anila honey
Greenhorn

Joined: Sep 11, 2008
Posts: 7
Hi All,


I am generating xml file using jdom.
As of now i did nt used any xml parsers.

now i want to remove xml Doctype and root element(<XMLRESPONSE>) from this file.


Result of above code is like this


[code]<?xml version="1.0" encoding="UTF-8"?>
<XMLResponse>

<categories>
<category label="8-2008" />
<category label="9-2008" />
<category label="10-2008" />
<category label="11-2008" />
<category label="12-2008" />
<category label="3-2008" />
<category label="6-2008" />
<category label="7-2008" />
<category label="3-2009" />
<category label="6-2009" />
<category label="8-2009" />
</categories>
<dataset seriesName="CENTRAL ATLANTIC">
<set value="76" />
<set value="54" />
<set value="74" />
<set value="88" />
<set value="78" />
<set value="80" />
<set value="69" />
<set />
<set />
<set />
<set />
</dataset>
<dataset seriesName="CENTRAL CORRIDOR">
<set />
<set />
<set />
<set />
<set />
<set />
<set />
<set value="86" />
<set value="80" />
<set value="69" />
<set />
</dataset>
<dataset seriesName="ULTRASOUND HQ">
<set />
<set />
<set />
<set />
<set />
<set />
<set />
<set />
<set />
<set />
<set value="100" />
</dataset>
</XMLResponse>[/code]


Now i want to remove,which marked with dark red in the above displayed xml file.

Let me know is there any way to do that.

Thanks,
Anila....


Thanks & Regards,
Anila...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18126
    
    8

That's not a DOCTYPE, that's the prolog. If you don't want it, there's probably a parameter in the serializer you used which allows you to exclude it. And you should realize that if you remove the root element, there won't be anything left in your document.

The point being, you're confusing an XML document -- which in JDOM is a tree structure consisting of elements and text and other things -- with its text representation when you serialize it. When you're working in JDOM you should think of it as a tree structure. In particular the tree structure doesn't contain start tags or end tags, it just contains elements.

If you really wanted to remove just the dark red lines and leave the black lines, then the result wouldn't be a well-formed XML document because it wouldn't have a root element. So you can't use any XML serializer to output such a thing and you can't even represent it in JDOM.

However if you really want such a document, and I suspect you might not really want it, you can produce it with an XSLT transformation.
anila honey
Greenhorn

Joined: Sep 11, 2008
Posts: 7
Hi,

How to use xslt???
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18126
    
    8

anila honey wrote:How to use xslt???


Could you ask a more specific question than that one? The answer to that one starts "First learn about XSLT..." and that isn't really very helpful, because you would have known that already.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generating xml by using Jdom,need to remove DOCTYPE and root element
 
Similar Threads
Parsing data out of an XML document
initBinder does not work as expected when I use annotations
Xml File generation - xstream
Java code to genarate xml ,for uncontinuous data....
Xstream xml from toXML give problem to display in javscript