xml-xmlbeans-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Eric Vasilik" <eric...@bea.com>
Subject RE: Resent: Making a copy of XmlObject
Date Fri, 30 Jul 2004 15:42:20 GMT
This fragment will create a new document, and copy the Customer element
and its contents to that new, empty, document.

XmlCursor cursor = xobj.newCursor();
XmlObject copy = XmlObject.Factory.newInstance();
XmlCursor target = copy.newCursor();
target.toNextToken();
cursor.copyXml( target );
target.dispose();
cursor.dispose();

You should now have a copy of your original fragment, with the Customer
element as the document element.

What "xobj.copy()" does is to copy the instance of the schema type
contained in the Customer element.  The customer element is not part of
that type -- it is merely a container for that type.

- Eric

> -----Original Message-----
> From: Saha, Sanjeev [mailto:SSaha@asce.org]
> Sent: Friday, July 30, 2004 6:20 AM
> To: xmlbeans-user@xml.apache.org
> Subject: Resent: Making a copy of XmlObject
> 
> I am kind of stuck without a resolution to this and will have to use
an
> implementation of dom4j that I wrote. Trouble is, dom4j takes around
180ms
> whereas xbeans requires only 20ms. Any insight into this will be
really
> helpful.
> 
> 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 it 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,
> 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/


- ---------------------------------------------------------------------
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/


Mime
View raw message