You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-user@xml.apache.org by "Saha, Sanjeev" <SS...@asce.org> on 2004/07/28 16:29:06 UTC

Making a copy of XmlObject

For the following xml fragment:

<Customer Id=''>
  <FirstName/>
  <LastName/>
</Customer>

When my program intercepts this fragment, the intent is to make a duplicate copy of this so as not to modify the original fragment. This duplication/copying is done in a separate api by passing the fragment as an XmlObject.

apiToCopyXmlObject(final XmlObject xobj)
{
  // my first attempt at copying
  return xobj.copy();
  // other attempts
  // XmlCursor cursor = xobj.newCursor();
  // return (XmlObject)cursor.getObject().copy();
}

As per the documentation, the copy api supposedly returns the same type as the current object, but as i turns out, it returns a Document instead of the <Customer> fragment. To overcome this, I try:

// attempt to get first child
XmlObject copy = xobj.copy();
XmlCursor cursor = copy.newCursor();
cursor.toFirstChild();
return cursor.getObject();

Sadly, the above code returns <FirstName/> and not the <Customer> fragment. Is the approach flawed?

Thanks in advance,
Sanjeev

- ---------------------------------------------------------------------
To unsubscribe, e-mail:   xmlbeans-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-user-help@xml.apache.org
Apache XMLBeans Project -- URL: http://xml.apache.org/xmlbeans/