You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@xmlbeans.apache.org by Maya Dahan <da...@hotmail.com> on 2007/05/17 21:19:11 UTC
Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
I am trying to work/populate the following XSD:
<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>
I am using the following code to set the values and examine the generated
XML:
NameDocument doc = NameDocument.Factory.newInstance();
Name name = doc.addNewName();
name.setNameValueArray(new String[] { "NameValue", "NameValue1" });
name.setNameElementArray(new String[] { "Name", "Name1" });
String text = doc.xmlText();
System.out.println(text);
The generated XML is not valid:
<Name>
<NameValue>NameValue</NameValue>
<NameValue>NameValue1</NameValue>
<NameElement>Name</NameElement>
<NameElement>Name1</NameElement>
</Name>
It should be:
<Name>
<NameValue>NameValue</NameValue>
<NameElement>Name</NameElement>
<NameValue>NameValue1</NameValue>
<NameElement>Name1</NameElement>
</Name>
Any ideas? Is this a bug? Is it fixed in a newer version of XMLBeans?
Thanks,
Maya
_________________________________________________________________
PC Magazines 2007 editors choice for best Web mailaward-winning Windows
Live Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_pcmag_0507
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Wing Yew Poon wrote:
> ...
>>
>> 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,
>
> ...
>
> 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.
>
Thanks for providing more details on the handling. In my remarks I was
responding to the earlier comments in this thread, which indicated there
was no difference in the generated data structures. And in fact, your
reply confirms this.
I realize that XMLBeans does a good job of structural validation when
reading in documents, but the fact that it generates data structures
which have to be used in a precise way in order to generate correct
output is definitely a mark against it. Basically XMLBeans requires the
user to understand the schema and assure that they only use the
generated data structures in accordance with the schema.
I believe this applies not only in the case we're discussing in this
thread, of a sequence with maxOccurs="unbounded", but to all the
XMLBeans generated code. I think that the ease with which XMLBeans
generates invalid output is the weakest part of the framework.
- Dennis
>
>> 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: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
RE: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Wing Yew Poon <wp...@bea.com>.
>From: Dennis Sosnoski <dm...@sosnoski.com>
>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: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Maya Dahan <da...@hotmail.com>.
I agree with Dennis; I was expecting that XMLBeans will create the structure
automatically for me.
In this particular use case XMLBeans prints the XML structure in the order I
set the element:
When setting NameValue first -
name.setNameValueArray(new String[] { "NameValue", "NameValue1" });
name.setNameElementArray(new String[] { "Name", "Name1" });
I get:
<Name>
<NameValue>NameValue</NameValue>
<NameValue>NameValue1</NameValue>
<NameElement>Name</NameElement>
<NameElement>Name1</NameElement>
</Name>
But, when I set NameValue second -
name.setNameElementArray(new String[] { "Name", "Name1" });
name.setNameValueArray(new String[] { "NameValue", "NameValue1" });
I get:
<Name>
<NameElement>Name</NameElement>
<NameElement>Name1</NameElement>
<NameValue>NameValue</NameValue>
<NameValue>NameValue1</NameValue>
</Name>
The XSD is not in my control so I cannot change it, any other suggestions?
>From: Dennis Sosnoski <dm...@sosnoski.com>
>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>
>
>If that's true it's a major flaw in XMLBeans, and pretty much rubbishes the
>schema support claim.
>
>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.
>
> - Dennis
>
>Dennis M. Sosnoski
>SOA and Web Services in Java
>Training and Consulting
>http://www.sosnoski.com - http://www.sosnoski.co.nz
>Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
>
>
>
>Stefan Offermann wrote:
>>Dennis Sosnoski schrieb:
>>>I'm confused by your statement. Elements in a <sequence> most definitely
>>>*are* ordered. Does this mean that XMLBeans ignores nested compositors?
>>
>>I'm sorry, elements in a sequence *are* *sorted*, shame on me for the
>>false information (When I learned xml-schema I was told that they are not
>>ordered, but they are as I read today...)
>>
>>The solution for Maya may be a schema which generates this output:
>>
>><Name>
>> <NameComponent>
>> <NameValue>NameValue</NameValue>
>> <NameElement>Name</NameElement>
>> </NameComponent>
>> <NameComponent>
>> <NameValue>NameValue1</NameValue>
>> <NameElement>Name1</NameElement>
>> </NameComponent>
>></Name>
>>
>>This would keep the order, but there is one more Type called
>>"NameComponent".
>>
>>Another solution could be:
>>
>><Name>
>> <NameComponent element="foo">fooValue</NameComponent>
>> <NameComponent element="bar">barValue</NameComponent>
>></Name>
>>
>>Best regards, Stefan
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>>For additional commands, e-mail: user-help@xmlbeans.apache.org
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
>For additional commands, e-mail: user-help@xmlbeans.apache.org
>
_________________________________________________________________
Like the way Microsoft Office Outlook works? Youll love Windows Live
Hotmail.
http://imagine-windowslive.com/hotmail/?locale=en-us&ocid=TXT_TAGHM_migration_HM_mini_outlook_0507
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Dennis Sosnoski <dm...@sosnoski.com>.
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>
If that's true it's a major flaw in XMLBeans, and pretty much rubbishes
the schema support claim.
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.
- Dennis
Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
Stefan Offermann wrote:
> Dennis Sosnoski schrieb:
>> I'm confused by your statement. Elements in a <sequence> most
>> definitely *are* ordered. Does this mean that XMLBeans ignores nested
>> compositors?
>
> I'm sorry, elements in a sequence *are* *sorted*, shame on me for the
> false information (When I learned xml-schema I was told that they are
> not ordered, but they are as I read today...)
>
> The solution for Maya may be a schema which generates this output:
>
> <Name>
> <NameComponent>
> <NameValue>NameValue</NameValue>
> <NameElement>Name</NameElement>
> </NameComponent>
> <NameComponent>
> <NameValue>NameValue1</NameValue>
> <NameElement>Name1</NameElement>
> </NameComponent>
> </Name>
>
> This would keep the order, but there is one more Type called
> "NameComponent".
>
> Another solution could be:
>
> <Name>
> <NameComponent element="foo">fooValue</NameComponent>
> <NameComponent element="bar">barValue</NameComponent>
> </Name>
>
> Best regards, Stefan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Stefan Offermann <of...@uni-muenster.de>.
Dennis Sosnoski schrieb:
> I'm confused by your statement. Elements in a <sequence> most definitely
> *are* ordered. Does this mean that XMLBeans ignores nested compositors?
I'm sorry, elements in a sequence *are* *sorted*, shame on me for the
false information (When I learned xml-schema I was told that they are
not ordered, but they are as I read today...)
The solution for Maya may be a schema which generates this output:
<Name>
<NameComponent>
<NameValue>NameValue</NameValue>
<NameElement>Name</NameElement>
</NameComponent>
<NameComponent>
<NameValue>NameValue1</NameValue>
<NameElement>Name1</NameElement>
</NameComponent>
</Name>
This would keep the order, but there is one more Type called
"NameComponent".
Another solution could be:
<Name>
<NameComponent element="foo">fooValue</NameComponent>
<NameComponent element="bar">barValue</NameComponent>
</Name>
Best regards, Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Dennis Sosnoski <dm...@sosnoski.com>.
Hi Stefan,
I'm confused by your statement. Elements in a <sequence> most definitely
*are* ordered. Does this mean that XMLBeans ignores nested compositors?
- Dennis
Dennis M. Sosnoski
SOA and Web Services in Java
Training and Consulting
http://www.sosnoski.com - http://www.sosnoski.co.nz
Seattle, WA +1-425-939-0576 - Wellington, NZ +64-4-298-6117
Stefan Offermann wrote:
> Maya Dahan schrieb:
>> I am trying to work/populate the following XSD:
>> <xs:sequence maxOccurs="unbounded">
>> <xs:element name="nameElement"
>> type="xs:string"/>
>> <xs:element name="nameValue" type="xs:string"/>
>> </xs:sequence>
>
>> The generated XML is not valid:
>> <Name>
>> <NameValue>NameValue</NameValue>
>> <NameValue>NameValue1</NameValue>
>> <NameElement>Name</NameElement>
>> <NameElement>Name1</NameElement>
>> </Name>
>
> The generated xml *is* valid!
>
>> It should be:
>> <Name>
>> <NameValue>NameValue</NameValue>
>> <NameElement>Name</NameElement>
>> <NameValue>NameValue1</NameValue>
>> <NameElement>Name1</NameElement>
>> </Name>
>>
>> Any ideas? Is this a bug? Is it fixed in a newer version of XMLBeans?
>
> It is "by-design" because elements in a sequence (your NameValue and
> NameElement) are *not* *ordered*. If you want to have
> Element-Value-pairs you should declare a new type in your schema which
> will have 1 element and 1 value, this new type can then be unbounded
> in you name-type.
>
> hope that helps, Stefan
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
> For additional commands, e-mail: user-help@xmlbeans.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org
Re: Sequence maxOccurs="unbounded" doesn't generate a valid XML (v2.0)
Posted by Stefan Offermann <of...@uni-muenster.de>.
Maya Dahan schrieb:
> I am trying to work/populate the following XSD:
> <xs:sequence maxOccurs="unbounded">
> <xs:element name="nameElement" type="xs:string"/>
> <xs:element name="nameValue" type="xs:string"/>
> </xs:sequence>
> The generated XML is not valid:
> <Name>
> <NameValue>NameValue</NameValue>
> <NameValue>NameValue1</NameValue>
> <NameElement>Name</NameElement>
> <NameElement>Name1</NameElement>
> </Name>
The generated xml *is* valid!
> It should be:
> <Name>
> <NameValue>NameValue</NameValue>
> <NameElement>Name</NameElement>
> <NameValue>NameValue1</NameValue>
> <NameElement>Name1</NameElement>
> </Name>
>
> Any ideas? Is this a bug? Is it fixed in a newer version of XMLBeans?
It is "by-design" because elements in a sequence (your NameValue and
NameElement) are *not* *ordered*. If you want to have
Element-Value-pairs you should declare a new type in your schema which
will have 1 element and 1 value, this new type can then be unbounded in
you name-type.
hope that helps, Stefan
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@xmlbeans.apache.org
For additional commands, e-mail: user-help@xmlbeans.apache.org