This week's giveaway is in the Groovy forum.
We're giving away four copies of Groovy Fundamentals video training course and have Ken Kousen on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes sorting XML to another XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Groovy Fundamentals video training course this week in the Groovy forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "sorting XML to another XML file" Watch "sorting XML to another XML file" New topic
Author

sorting XML to another XML file

Francesco Marchioni
author
Ranch Hand

Joined: Sep 22, 2003
Posts: 191
Hi all,
I need to sort an XML document depending on the value of some attributes inside it.
I decided to :

1) iterate through the XML
2) save the XML Nodes I'm interested with in a Vector
3) order Nodes in the vector
3) create a new XML using nodes from the Vector.

The problem is, once I import & append nodes in the new XML I get an error

org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

The code I use to re-create the XML is the following:



I have tried also cloning the Node




but still the same error.
Can anybody help me ?
Thanks
Francesco


WildFly 8 Administration Book - JBoss Tutorials
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12955
    
    5

I think you are using that incorrectly - the API says this call returns a new copy of the node without changing the original. So you should do something like:

Bill
 
Don't get me started about those stupid light bulbs.
 
subject: sorting XML to another XML file