>From: Dennis Sosnoski <[EMAIL PROTECTED]>
>Reply-To: user@xmlbeans.apache.org
>To: user@xmlbeans.apache.org
>Subject: Re: Sequence maxOccurs="unbounded" doesn't generate a valid
XML 
>(v2.0)
>Date: Sun, 20 May 2007 09:17:11 +1200
>
>XMLBeans claims "100% support of XML Schema". But from what I've seen
in 
>this thread, it appears to ignore the internal structure of
complexTypes, 
>so that this:
>
>            <xs:element name="name">
>                <xs:complexType>
>                    <xs:sequence maxOccurs="unbounded">
>                        <xs:element name="nameElement"
type="xs:string"/>
>                        <xs:element name="nameValue" type="xs:string"/>
>                    </xs:sequence>
>                </xs:complexType>
>            </xs:element>
>
>is intentionally treated the same as this:
>
>            <xs:element name="name">
>                <xs:complexType>
>                    <xs:sequence>
>                        <xs:element name="nameElement" 
>maxOccurs="unbounded" type="xs:string"/>
>                        <xs:element name="nameValue"
maxOccurs="unbounded" 
>type="xs:string"/>
>                    </xs:sequence>
>                </xs:complexType>
>            </xs:element>
>
Dennis is incorrect in his statement above. XMLBeans does NOT ignore the
internal structure, and it does NOT conflate the two different
definitions
above. If you parse an instance of the second schema using the
NameDocument.Factory
for the first schema or vice versa, XMLBeans will tell you that the
instance
is invalid.

>I realize that by changing the schema you can manipulate XMLBeans into 
>producing something that creates the intended XML structure. But the
reason 
>people use XMLBeans in the first place is because it's supposed to
create 
>that structure automatically.
>
Dahan,
You do not have to change the schema.
The correct way to get what you want is as follows:

        NameDocument doc = NameDocument.Factory.newInstance();
        NameDocument.Name name = doc.addNewName();
        name.addNameElement("Name1");
        name.addNameValue("Value1");
        name.addNameElement("Name2");
        name.addNameValue("Value2");
        name.addNameElement("Name3");
        name.addNameValue("Value3");
        String text = doc.xmlText(new
XmlOptions().setSavePrettyPrint());
        System.out.println(text);
        System.out.println(doc.validate());

The result is:

<dah:name xmlns:dah="dahan">
  <nameElement>Name1</nameElement>
  <nameValue>Value1</nameValue>
  <nameElement>Name2</nameElement>
  <nameValue>Value2</nameValue>
  <nameElement>Name3</nameElement>
  <nameValue>Value3</nameValue>
</dah:name>
true

XMLBeans doesn't do everything automagically for you. Schemas can get
extremely
complicated. But it provides enough flexibility so that you can get the
right thing 
- or get the wrong thing too if that's what you want.

Wing Yew Poon

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to