[jdom-interest] Error handling

Bradley S. Huffman hip at a.cs.okstate.edu
Mon Jan 3 08:24:56 PST 2005


Either detach the problem ChildNode from the original document or clone a
copy of it before adding to the new document.

Brad

"Scott Ellis" writes:

> All,
> 
> I have an xml document that contains a root node and several children as
> such:
> 
> <RootNode>
>     <ChildNode>
>     <ChildNode>
>     ...
> </RootNode>
> 
> I parse this document, iterate the children, then attempt to apply ChildNode
> to the database.  If there are any problems with the processing of ChildNode
> to the database due to any SQL error, I create another document that has the
> same structure, but contains only the ChildNode elements for which problems
> occurred.  Then I write this new document to the file system in an error
> directory.
> 
> This used to work, but it seems now that I changed something that is giving
> me a problem.  The error reads something like  -- The Content already has an
> existing parent "RootNode" --
> 
> I know the reason is that the ChildNode is already parsed and has an
> existing parent from the parsed document, and that the new parent I am
> creating has the same named parent, the question is how to get around it.
> 
> I create the document like this:
> 
> Element root = new Element( "RootNode" );
> Document doc = new Document( root );
> root.addContent( parsedElemFromOriginalDocument );
> 
> Help?
> 
> Thanks,
> Scott
> 
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://www.jdom.org/mailman/options/jdom-interest/youraddr@yourhost.com


More information about the jdom-interest mailing list