File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes DOMSource? 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 "DOMSource?" Watch "DOMSource?" New topic
Author

DOMSource?

thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
Could someone show me how to make the following codes to print out only once?

=========
For example, the code above prints

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SevenDwarfs>
<Row>
<name>Dopey</name>
<status>youngest</status>
</Row>
</SevenDwarfs>
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SevenDwarfs>
<Row>
<name>Dopey</name>
<status>youngest</status>
</Row>
<Row>
<name>Doc</name>
<status>oldest</status>
</Row>
</SevenDwarfs>

==========
I would like to have only the latter portion printed as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SevenDwarfs>
<Row>
<name>Dopey</name>
<status>youngest</status>
</Row>
<Row>
<name>Doc</name>
<status>oldest</status>
</Row>
</SevenDwarfs>
=========
Also, how can I get rid of "<?xml version="1.0" encoding="UTF-8" standalone="no"?>" and just have the rootNode(<SevenDwarfs>) and the children nodes? I think it might have something to do with the way DOMSource is setup but I could be wrong. TIA.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

It would be a lot easier to read your code if it had been posted inside the "Code" tags (see the "Code" button above the box you post in?) and somebody might even read the whole thing if you edited your post to do that. Unindented code is very hard to read.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Your main method creates two XML trees (lines 79, 83)--what would you expect?
thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
Thanks for reading, but if I take out line 79, it prints as follows:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SevenDwarfs>
<Row>
<name>Doc</name>
<status>oldest</status>
</Row>
</SevenDwarfs>

That is not what I want.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Sorry, I didn't dig through the convoluted code enough.

Your createXMLRecords method is doing too many things: it both creates the XML records *and* does the transformation. You should only do the transformation once, at the very end.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(The root node creation code also does too much. A method should do only one thing, do it well, and do it completely... but no more.)
thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
I extracted line 66-70 to made another method which was called after line 83, but still I got the following printout:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SevenDwarfs>
<Row>
<name>Doc</name>
<status>oldest</status>
</Row>
</SevenDwarfs>
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please post the current code (UseCodeTags).
thomas silver
Ranch Hand

Joined: Jun 20, 2003
Posts: 32
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I get this:(Once I add transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");, depending on your transformer implementation.) What's the difference between that and what you want?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOMSource?