It all depends on how you constructed the XMLBean document. This is how XMLBeans deals with prefixes:

  1. if created from text xml, i.e. parse(), will keep the existing prefixes and namespace declarations around as much as possible.
  2. if created with newInstance()/addNew(), there will be uri-s for elements’ and attributes’ QNames but namespace declarations and prefixes will no be set in the document.

Only when saved to text, the saver will synthesize prefixes and namespace declarations to generate a syntactically correct XML document.

 

If you are in case 2. and ask for the getDomNode you will get a live Dom Node which, depending how your Dom saver works, might marshal it in a different text representation. On the other hand newDomNode() will engage the saver.

 

If you want prefixes and namespace declarations in the live DOM representation, they have to exist in the XmlBean’s store. Ways to do that are:

  1. use Factory.parse() methods
  2. use XmlCursor’s insertAttributeXXX(QName) and insertElementXXX(Qname), where QName contains a prefix and insertNamespace() for namespace declarations.

 

Cezar

 


From: Vinh Nguyen (vinguye2) [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 09, 2006 4:54 PM
To: dev@xmlbeans.apache.org
Subject: RE: XmlObject getDomNode fails to preserve namespace prefix

 

Anyone know if this is a bug or expected behavior?  I should mention that I'm using XmlBeans 2.2.0.

 


From: Vinh Nguyen (vinguye2)
Sent: Thursday, November 09, 2006 9:05 AM
To: dev@xmlbeans.apache.org
Subject: XmlObject getDomNode fails to preserve namespace prefix

Hi all,

There seems to be an issue with the getDomNode() method in the generated beans in that it fails to preserve the namespace prefix.  I would expect the method to preserve all xml artifacts of the existing object, but it doesn't seem to be.  On the other hand, the newDomNode() method does preserve the prefix.  What is the proper way for getting the original xml node representation of the object, without having to create a new node?

 

For example, my BoxDocument and BoxType classes were generated from an xsd.  Here's the various xml test outputs:

 

**XML from boxDoc.xmlText():
<box:Box xmlns:box="http://demo/schemas/box"><box:width>123</box:width><box:height>123</box:height></box:Box>

**XML from boxDoc.getDomNode():
<?xml version="1.0" encoding="UTF-8"?>
<Box xmlns="http://demo/schemas/box">
    <width>123</width>
    <height>123</height>
</Box>

 

**XML from boxDoc.newDomNode():
<?xml version="1.0" encoding="UTF-8"?>
<box:Box xmlns:box="http://demo/schemas/box">
    <box:width>123</box:width>
    <box:height>123</box:height>
</box:Box>

Any help is appreciated, thanks!

-Vinh

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

Reply via email to