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