aspose file tools*
The moose likes XML and Related Technologies and the fly likes adding node to doc Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "adding node to doc" Watch "adding node to doc" New topic
Author

adding node to doc

Guru Vasu
Greenhorn

Joined: Nov 11, 2006
Posts: 9

Hi,

I am new to XML/XSLT and I am trying to do the following and I receive a WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.

I was able to see the logic behind it and use doc.importNode(child, true) and that didnt work.

I would appreciate any help/advice.





thank you
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

"true cube", welcome to JavaRanch. We're friendly here, but we do require members to have valid display names.

Display names must be at least two words: your first name and your last name. Fictitious names are not allowed.

Please edit your profile and correct your display name since accounts with invalid display names will be closed.

(And it would also help if you could explain what "didn't work" meant in your original post.)
Guru Vasu
Greenhorn

Joined: Nov 11, 2006
Posts: 9

Hi Paul,

Thank you for your reply. Just updated my profile.

the error that I was getting was WRONG_DOCUMENT_ERR: A node is used in a different document -- which I just managed to fix by chagning my code to


from



But got a java.lang.UnsupportedOperationException. Here is what I am trying to do.

Extending AbstractXsltView, I am trying to domify my objects and add it to the model object

Here is my code



Do you (or anyone) know of a way to achieve the same in any fashion. Spring website provides an example which works for me (but its too simple for me to use it to comprehend the problem in the above situation).

Thank you for your help in advance
Guru
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18155
    
    8

Your document already has a root node, right? And an XML document can only have one root node. So when you try to add another child to the document, you are violating that rule. Probably you meant to add that node somewhere lower in the tree.
Guru Vasu
Greenhorn

Joined: Nov 11, 2006
Posts: 9

Yes you are right .. took a while for me to figure that out - but commented out the code (//Element rootElement = doc.createElement(root);) and I was able to append the node to the doc.

but now I am getting a java.lang.UnsupportedException - when Spring tries to render the page out - which is generated from NodeAdapter(from Domify jar)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding node to doc
 
Similar Threads
node type text
session variable
ClassCastException
append an element to a text node using jdom?
Make HashMap elements fit into an ArrayList