You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Radu Preotiuc-Pietro <ra...@bea.com> on 2008/03/11 22:25:26 UTC

Re: Parsing DOM-Node to specific XMLBean delivers always the root-node twice

I have been meaning to answer this...

XmlOptions.SET_SAVE_INNER inside the parse() method won't help of
course, because it is a "SAVE" option. It doesn't even get looked at for
parse.

What you need to make sure is that the "node" parameter looks like:

<subjectConfirmation></subjectConfirmation>
(or maybe
<xml-fragment><subjectConfirmation></subjectConfirmation></xml-fragment>)

What is probably happening in your case is that "node" looks like:
<subject>
               <subjectConfirmation>

So when you call assertionBean.setSubject() you get one <subject>
element inserted by the setter and one from your parsed document, for a
total of two.

To understand why that is the case, consider an element <stringElem> of
type "xs:string". In order to set it you would call:

xmlObject.setStringElem("a string");

and not

xmlObject.setStringElem(stringXmlElement);

You supply just the "content" and XmlBeans inserts the element, based on
what setter you called (there could be of course many setters with the
same type as parameter, so you would get different element names for the
same input based on where you set it).

Same thing with complex types, you need to provide the content and the
element name is set automatically for you.

How does <xml-fragment> fit it? Well, assume that your content is

<subjectConfirmation/>
<subjectCancellation/>

If you saved it like that, it would not be well-formed XML, so then
<xml-fragment> is added as root. When parsing, XMLBeans "knows" that
<xml-fragment> is to be ignored (this element is "special" to XMLBeans)
and it won't show up in the final document.

Radu

On Tue, 2008-02-26 at 01:01 -0800, Christian Mielke wrote:
> Hello,
> 
> I want to parse a DOM-Node into a specific XMLBean. The XMLBean is a
> member of an other XMLBean. When I parse the include node into the
> bean and add it to the outer bean, this inner bean it's root element
> always twice.
> 
> This looks like this:
> 
> <assertion>
> 
>      <subject>
> 
>           <subject>
> 
>                <subjectConfirmation>
> 
> Assertion is the outer XMLBean and subject the inner XMLBean.  
> 
> I create the subject XMLBean as following:
> assertionBean.setSubject(SubjectBean.Factory.parse(node));
> 
> I tried also XMLOptions.SET_SAVE_INNER inside the parse-method. Must I
> use an other option? Or do I have to parse the DOM-node on another
> type?
> 
> Greetings
> 
> Christian
> 
>  
> 

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.

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