[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xmlbeans-dev
Subject:    RE: XmlObject getDomNode fails to preserve namespace prefix
From:       "Cezar Andrei" <cezar () bea ! com>
Date:       2006-11-10 14:38:16
Message-ID: 99479F4D39C9244F8E17E688193A3DD8010C16A9 () repbex02 ! amer ! bea ! com
[Download RAW message or body]

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:vinguye2@cisco.com] 
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:heigh
t>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.

[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:st1="urn:schemas-microsoft-com:office:smarttags" \
xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
 namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
span.EmailStyle17
	{mso-style-type:personal-reply;
	font-family:Arial;
	color:navy;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
 /* List Definitions */
 @list l0
	{mso-list-id:2028749304;
	mso-list-type:hybrid;
	mso-list-template-ids:811468500 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l0:level1
	{mso-level-tab-stop:.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
@list l1
	{mso-list-id:2118602262;
	mso-list-type:hybrid;
	mso-list-template-ids:-607490822 67698703 67698713 67698715 67698703 67698713 \
67698715 67698703 67698713 67698715;} @list l1:level1
	{mso-level-tab-stop:.5in;
	mso-level-number-position:left;
	text-indent:-.25in;}
ol
	{margin-bottom:0in;}
ul
	{margin-bottom:0in;}
-->
</style>

</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>It all depends on how you constructed the
XMLBean document. This is how XMLBeans deals with \
prefixes:<o:p></o:p></span></font></p>

<ol style='margin-top:0in' start=1 type=1>
 <li class=MsoNormal style='color:navy;mso-list:l1 level1 lfo1'><font size=2
     color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial'>if
     created from text xml, i.e. parse(), will keep the existing prefixes and
     namespace declarations around as much as possible.<o:p></o:p></span></font></li>
 <li class=MsoNormal style='color:navy;mso-list:l1 level1 lfo1'><font size=2
     color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial'>if
     created with newInstance()/addNew(), there will be uri-s for elements&#8217;
     and attributes&#8217; QNames but namespace declarations and prefixes will
     no be set in the document.<o:p></o:p></span></font></li>
</ol>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Only when saved to text, the saver will \
synthesize prefixes and namespace declarations to generate a syntactically correct \
XML document.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>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.<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>If you want prefixes and namespace
declarations in the live DOM representation, they have to exist in the \
XmlBean&#8217;s store. Ways to do that are:<o:p></o:p></span></font></p>

<ol style='margin-top:0in' start=1 type=1>
 <li class=MsoNormal style='color:navy;mso-list:l0 level1 lfo2'><font size=2
     color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial'>use
     Factory.parse() methods<o:p></o:p></span></font></li>
 <li class=MsoNormal style='color:navy;mso-list:l0 level1 lfo2'><font size=2
     color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial'>use
     XmlCursor&#8217;s insertAttributeXXX(QName) and insertElementXXX(Qname),
     where QName contains a prefix and insertNamespace() for namespace
     declarations.<o:p></o:p></span></font></li>
</ol>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'>Cezar<o:p></o:p></span></font></p>

<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p>&nbsp;</o:p></span></font></p>

<div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'>

<div>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabindex=-1>

</span></font></div>

<p class=MsoNormal><b><font size=2 face=Tahoma><span style='font-size:10.0pt;
font-family:Tahoma;font-weight:bold'>From:</span></font></b><font size=2
face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> Vinh Nguyen
(vinguye2) [mailto:vinguye2@cisco.com] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, November 09, 2006
4:54 PM<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName \
w:st="on">dev@xmlbeans.apache.org</st1:PersonName><br> <b><span \
style='font-weight:bold'>Subject:</span></b> RE: XmlObject getDomNode fails to \
preserve namespace prefix</span></font><o:p></o:p></p>

</div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<p class=MsoNormal><font size=2 color=blue face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:blue'>Anyone know if this is&nbsp;a bug or
expected behavior?&nbsp; I&nbsp;should mention that I'm using XmlBeans \
2.2.0.</span></font><o:p></o:p></p>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'><o:p>&nbsp;</o:p></span></font></p>

<div class=MsoNormal align=center style='text-align:center'><font size=3
face="Times New Roman"><span style='font-size:12.0pt'>

<hr size=2 width="100%" align=center tabIndex=-1>

</span></font></div>

<p class=MsoNormal style='margin-bottom:12.0pt'><b><font size=2 face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma;font-weight:bold'>From:</span></font></b><font
 size=2 face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma'> Vinh
Nguyen (vinguye2) <br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, November 09, 2006
9:05 AM<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName \
w:st="on">dev@xmlbeans.apache.org</st1:PersonName><br> <b><span \
style='font-weight:bold'>Subject:</span></b> XmlObject getDomNode fails to preserve \
namespace prefix</span></font><o:p></o:p></p>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Hi all,</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>There seems to be an issue with the getDomNode() method in
the&nbsp;generated&nbsp;beans in that it fails to preserve the namespace
prefix.&nbsp; I would expect the method to preserve all xml artifacts of the
existing object, but it doesn't seem to be.&nbsp; On the other hand, the
newDomNode() method does preserve the prefix.&nbsp; What is the proper way for
getting the original xml node representation of the object, without having to
create a new node?</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>For example, my BoxDocument and BoxType classes&nbsp;were
generated from an xsd.&nbsp; Here's the various xml \
test&nbsp;outputs:</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>**XML from boxDoc.xmlText():<br>
&lt;box:Box
xmlns:box=&quot;http://demo/schemas/box&quot;&gt;&lt;box:width&gt;123&lt;/box:width&gt \
;&lt;box:height&gt;123&lt;/box:height&gt;&lt;/box:Box&gt;</span></font><o:p></o:p></p>


</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>**XML from boxDoc.getDomNode():<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&lt;Box xmlns=&quot;http://demo/schemas/box&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;width&gt;123&lt;/width&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;height&gt;123&lt;/height&gt;<br>
&lt;/Box&gt;</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=3 face="Times New Roman"><span style='font-size:
12.0pt'>&nbsp;<o:p></o:p></span></font></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>**XML from boxDoc.newDomNode():<br>
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>
&lt;box:Box xmlns:box=&quot;http://demo/schemas/box&quot;&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;box:width&gt;123&lt;/box:width&gt;<br>
&nbsp;&nbsp;&nbsp; &lt;box:height&gt;123&lt;/box:height&gt;<br>
&lt;/box:Box&gt;</span></font><o:p></o:p></p>

</div>

<div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>Any help is appreciated, thanks!</span></font><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt;
font-family:Arial'>-Vinh</span></font><o:p></o:p></p>

</div>

</div>

</div>

</div>

</body>

</html>
<PRE>_______________________________________________________________________
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.
</PRE>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic