You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by first last <gu...@gmail.com> on 2009/10/05 10:33:26 UTC

How to convert from org.apache.xmlbeans.xmlobject to org.w3c.dom.Document?

Hi all,I'm using XMLBeans to create an XML object which is of type
org.apache.xmlbeans.xmlobject.
But I need to pass this XML content to an API which expects an XML of type -
org.w3c.dom.Document. Does XMLBeans provide a direct way of converting from
xmlobject to dom.Document? I noticed that we can go from XmlObject to
org.w3c.dom Node Object using XmlObject.newDomNode(), but not sure how to
get a dom.Document object from XMLobject. Can someone let me know if this is
possible?

Thanks in advance for your help.

Regards,
Gugle

Re: How to convert from org.apache.xmlbeans.xmlobject to org.w3c.dom.Document?

Posted by first last <gu...@gmail.com>.
Thanks a lot Jeff. My xmlobj is indeed at the document level. I'll try the
approach you've suggested. Thanks again.
Gugle.

On Mon, Oct 5, 2009 at 3:33 PM, Jeff Lusted <jl...@star.le.ac.uk> wrote:

> Hi Gugle!
>
> Yes indeed, that is what I am suggesting, provided the xmlobj you create
> is at the document level, I believe. (So the token source would be the
> equivalent of XmlCursor.TokenType  of STARTDOC ... the singleton
> start-document token type). I don't think the cast will be correct
> otherwise.
>
> Regards
> Jeff
>
> On Mon, 2009-10-05 at 15:09 +0530, first last wrote:
> > Hi Jeff,
> > Thanks for the quick respons. Are you suggesting that I do the
> > following?
> >
> >
> > org.apache.xmlbeans.xmlobject xmlObj = null;
> > ...
> > create/populate the xmlObj
> > ....
> > //directly typecast the xmlobj to Document
> > org.w3c.dom.Document nd = (Document) xmlObj.getDomNode();
> >
> >
> > Is this correct?
> >
> >
> > Regards,
> > Gugle
> >
> >
> >
> >
> > On Mon, Oct 5, 2009 at 2:50 PM, Jeff Lusted <jl...@star.le.ac.uk>
> > wrote:
> >         Hi Gugle!
> >
> >
> >         On Mon, 2009-10-05 at 14:03 +0530, first last wrote:
> >         > Hi all,
> >         > I'm using XMLBeans to create an XML object which is of
> >         > type org.apache.xmlbeans.xmlobject. But I need to pass this
> >         XML
> >         > content to an API which expects an XML of type -
> >         org.w3c.dom.Document.
> >         > Does XMLBeans provide a direct way of converting from
> >         xmlobject to
> >         > dom.Document? I noticed that we can go from XmlObject to
> >         org.w3c.dom
> >         > Node Object using XmlObject.newDomNode(), but not sure how
> >         to get a
> >         > dom.Document object from XMLobject. Can someone let me know
> >         if this is
> >         > possible?
> >
> >
> >         My understanding is that if you use the XmlObject that is the
> >         equivalent
> >         of the document interface, then yourXmlObject.getDomNode()
> >         should return
> >         the correct Dom Node and this used tocast to a
> >         org.w3c.dom.Document...
> >
> >         >From the api...
> >
> >         > public Node getDomNode()
> >         >
> >         >
> >         > Returns a W3C DOM Node containing the XML represented by
> >         this source.
> >         > This is a live DOM node, not a copy. Any changes made
> >         through this
> >         > node are immediately reflected in the document associated
> >         with this
> >         > token source. Depending on the kind of token this
> >         XmlTokenSource
> >         > represents, an appropriate node will be returned.
> >
> >         Haven't tried this any time recently. Hope my understanding is
> >         good.
> >         Regards
> >         Jeff
> >         --
> >         Jeff Lusted               tel: +44 (0)116 252 3581
> >         Astrogrid Project         mob: +44 (0)7941 599062
> >         Dept Physics & Astronomy  email: jl99@star.le.ac.uk
> >         University of Leicester   web: http://www.astrogrid.org
> >
> >
> >
> ---------------------------------------------------------------------
> >         To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> >         For additional commands, e-mail: user-help@xmlbeans.apache.org
> >
> >
> >
> --
> Jeff Lusted               tel: +44 (0)116 252 3581
> Astrogrid Project         mob: +44 (0)7941 599062
> Dept Physics & Astronomy  email: jl99@star.le.ac.uk
> University of Leicester   web: http://www.astrogrid.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

Re: How to convert from org.apache.xmlbeans.xmlobject to org.w3c.dom.Document?

Posted by Jeff Lusted <jl...@star.le.ac.uk>.
Hi Gugle!

Yes indeed, that is what I am suggesting, provided the xmlobj you create
is at the document level, I believe. (So the token source would be the
equivalent of XmlCursor.TokenType  of STARTDOC ... the singleton
start-document token type). I don't think the cast will be correct
otherwise.

Regards
Jeff

On Mon, 2009-10-05 at 15:09 +0530, first last wrote:
> Hi Jeff,
> Thanks for the quick respons. Are you suggesting that I do the
> following?
> 
> 
> org.apache.xmlbeans.xmlobject xmlObj = null;
> ...
> create/populate the xmlObj
> ....
> //directly typecast the xmlobj to Document
> org.w3c.dom.Document nd = (Document) xmlObj.getDomNode();
> 
> 
> Is this correct?
> 
> 
> Regards,
> Gugle
> 
> 
> 
> 
> On Mon, Oct 5, 2009 at 2:50 PM, Jeff Lusted <jl...@star.le.ac.uk>
> wrote:
>         Hi Gugle!
>         
>         
>         On Mon, 2009-10-05 at 14:03 +0530, first last wrote:
>         > Hi all,
>         > I'm using XMLBeans to create an XML object which is of
>         > type org.apache.xmlbeans.xmlobject. But I need to pass this
>         XML
>         > content to an API which expects an XML of type -
>         org.w3c.dom.Document.
>         > Does XMLBeans provide a direct way of converting from
>         xmlobject to
>         > dom.Document? I noticed that we can go from XmlObject to
>         org.w3c.dom
>         > Node Object using XmlObject.newDomNode(), but not sure how
>         to get a
>         > dom.Document object from XMLobject. Can someone let me know
>         if this is
>         > possible?
>         
>         
>         My understanding is that if you use the XmlObject that is the
>         equivalent
>         of the document interface, then yourXmlObject.getDomNode()
>         should return
>         the correct Dom Node and this used tocast to a
>         org.w3c.dom.Document...
>         
>         >From the api...
>         
>         > public Node getDomNode()
>         >
>         >
>         > Returns a W3C DOM Node containing the XML represented by
>         this source.
>         > This is a live DOM node, not a copy. Any changes made
>         through this
>         > node are immediately reflected in the document associated
>         with this
>         > token source. Depending on the kind of token this
>         XmlTokenSource
>         > represents, an appropriate node will be returned.
>         
>         Haven't tried this any time recently. Hope my understanding is
>         good.
>         Regards
>         Jeff
>         --
>         Jeff Lusted               tel: +44 (0)116 252 3581
>         Astrogrid Project         mob: +44 (0)7941 599062
>         Dept Physics & Astronomy  email: jl99@star.le.ac.uk
>         University of Leicester   web: http://www.astrogrid.org
>         
>         
>         ---------------------------------------------------------------------
>         To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>         For additional commands, e-mail: user-help@xmlbeans.apache.org
>         
> 
> 
-- 
Jeff Lusted               tel: +44 (0)116 252 3581
Astrogrid Project         mob: +44 (0)7941 599062
Dept Physics & Astronomy  email: jl99@star.le.ac.uk
University of Leicester   web: http://www.astrogrid.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org


Re: How to convert from org.apache.xmlbeans.xmlobject to org.w3c.dom.Document?

Posted by first last <gu...@gmail.com>.
Hi Jeff,Thanks for the quick respons. Are you suggesting that I do the
following?

org.apache.xmlbeans.xmlobject xmlObj = null;
...
create/populate the xmlObj
....
//directly typecast the xmlobj to Document
org.w3c.dom.Document nd = (Document) xmlObj.getDomNode();

Is this correct?

Regards,
Gugle



On Mon, Oct 5, 2009 at 2:50 PM, Jeff Lusted <jl...@star.le.ac.uk> wrote:

> Hi Gugle!
>
> On Mon, 2009-10-05 at 14:03 +0530, first last wrote:
> > Hi all,
> > I'm using XMLBeans to create an XML object which is of
> > type org.apache.xmlbeans.xmlobject. But I need to pass this XML
> > content to an API which expects an XML of type - org.w3c.dom.Document.
> > Does XMLBeans provide a direct way of converting from xmlobject to
> > dom.Document? I noticed that we can go from XmlObject to org.w3c.dom
> > Node Object using XmlObject.newDomNode(), but not sure how to get a
> > dom.Document object from XMLobject. Can someone let me know if this is
> > possible?
>
> My understanding is that if you use the XmlObject that is the equivalent
> of the document interface, then yourXmlObject.getDomNode() should return
> the correct Dom Node and this used tocast to a org.w3c.dom.Document...
>
> >From the api...
>
> > public Node getDomNode()
> >
> >
> > Returns a W3C DOM Node containing the XML represented by this source.
> > This is a live DOM node, not a copy. Any changes made through this
> > node are immediately reflected in the document associated with this
> > token source. Depending on the kind of token this XmlTokenSource
> > represents, an appropriate node will be returned.
>
> Haven't tried this any time recently. Hope my understanding is good.
> Regards
> Jeff
> --
> Jeff Lusted               tel: +44 (0)116 252 3581
> Astrogrid Project         mob: +44 (0)7941 599062
> Dept Physics & Astronomy  email: jl99@star.le.ac.uk
> University of Leicester   web: http://www.astrogrid.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>

Re: How to convert from org.apache.xmlbeans.xmlobject to org.w3c.dom.Document?

Posted by Jeff Lusted <jl...@star.le.ac.uk>.
Hi Gugle!

On Mon, 2009-10-05 at 14:03 +0530, first last wrote:
> Hi all,
> I'm using XMLBeans to create an XML object which is of
> type org.apache.xmlbeans.xmlobject. But I need to pass this XML
> content to an API which expects an XML of type - org.w3c.dom.Document.
> Does XMLBeans provide a direct way of converting from xmlobject to
> dom.Document? I noticed that we can go from XmlObject to org.w3c.dom
> Node Object using XmlObject.newDomNode(), but not sure how to get a
> dom.Document object from XMLobject. Can someone let me know if this is
> possible?

My understanding is that if you use the XmlObject that is the equivalent
of the document interface, then yourXmlObject.getDomNode() should return
the correct Dom Node and this used tocast to a org.w3c.dom.Document...

>>From the api...

> public Node getDomNode()
> 
> 
> Returns a W3C DOM Node containing the XML represented by this source.
> This is a live DOM node, not a copy. Any changes made through this
> node are immediately reflected in the document associated with this
> token source. Depending on the kind of token this XmlTokenSource
> represents, an appropriate node will be returned. 

Haven't tried this any time recently. Hope my understanding is good.
Regards
Jeff
-- 
Jeff Lusted               tel: +44 (0)116 252 3581
Astrogrid Project         mob: +44 (0)7941 599062
Dept Physics & Astronomy  email: jl99@star.le.ac.uk
University of Leicester   web: http://www.astrogrid.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org