473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

[XML Schema] Error "content model is not determinist"

Hello,

I'd like to write a single XML Schema for both these documents :

<Items>
<Item xml:id="id1">
<Name>ABC</Name>
...
</Item>
<Item xml:id="id2">
<Name>DEF</Name>
...
</Item>
...
</Items>

and

<Items>
<Item ref="id1"/>
<Item ref="id2"/>
...
</Items>

That looks "easy", but I've been googling for hours and tried so many
differents combinations of <choiceand <sequence>'s... and yet it
doesn't work :/
All I got at best were errors saying "local complex type: The content
model is not determinist" -- because the element name "Item" is used in
both "types" of elements IIUC.

Maybe using more complex OO features of XML Schema would somehow help me
out?

Cheers,

--
Damiano ALBANI
Aug 21 '06 #1
5 7126
Damiano ALBANI wrote:
Hello,

I'd like to write a single XML Schema for both these documents :
....

How about a schema that declares:
- Items elements to contain any number of Item elements (maybe any
number 0, up to you)
- Item elements to have an optional id attribute, an optional ref
attribute and a sequence of Name sub-elements of length 0 or 1
That looks "easy", but I've been googling for hours and tried so many
differents combinations of <choiceand <sequence>'s... and yet it
doesn't work :/
You will have to tell us about what it must be able to do, what you
tried, what you expected and what you got....

One solution is to approximate Items to contain anything at all. That
will work -- but is that good enough for your requirements?
All I got at best were errors saying "local complex type: The content
model is not determinist" -- because the element name "Item" is used in
both "types" of elements IIUC.

Maybe using more complex OO features of XML Schema would somehow help me
out?
NO. They will only make it worse ;)

An XML Schema must be written in such a way that it can be <<determined
immediately when parsing what branch of a content model to use>(my
formulation; The XML Schema spec has some formally correct but so
complicated that you can't read it ways to say that).

Example

<element name="goat">
<complexType>
<choice>
<sequence>
<element name="foo"/>
<element name="bar"/>
</sequence>
<sequence>
<element name="foo"/>
<element name="baz"/>
</sequence>
</choice>
</complexType>
</element>

--- when validating:
<goat>
<foo/>
<baz/>
</goat>

(which is valid), the schema must be constructed that the validator,
when it sees the <foo/element, does not have to _guess_ whether to
continue validating as
<sequence>
<element name="foo"/>
<element name="bar"/>
</sequence>

or

<sequence>
<element name="foo"/>
<element name="baz"/>
</sequence>

You have probably made that mistake ;)

A possible fix is:

<element name="goat">
<complexType>
<sequence>
<element name="foo"/>
<choice>
<element name="bar"/>
<element name="baz"/>
</choice>
</sequence>
</complexType>
</element>
Hope that helped.

Søren
Aug 21 '06 #2
Thanks for the tips Soren !

Here's what I wrote, which works quite well -- not perfectly, but the
best I could thought of :

<xsd:group name="Item_Content">
<xsd:sequence>
<xsd:element name="Name"
type="xsd:string"/>
<xsd:element name="Type"
type="xsd:string"/>
...
</xsd:sequence>
</xsd:group>
<xsd:complexType name="Item_Type">
<xsd:group ref="Item_Content"
minOccurs="0"
maxOccurs="1"/>
<xsd:attribute name="id"
type="xsd:ID"/>
<xsd:attribute name="ref"
type="xsd:IDREF"/>
</xsd:complexType>

So, the only problem is that an Item element with both (content + @id)
_and_ @ref attribute is considered valid.

In my real-world application, I don't manipulate simply Item elements
but there's several complex element types. So that means I need to write
many "dual" element definitions (content through <xsd:group+ actual
type referring to that group). As I'm no expert in XML Schema, would
there be a way to avoid this redundancy ?

Cheers,

--
Damiano ALBANI
Aug 22 '06 #3
Damiano ALBANI wrote:
Thanks for the tips Soren !
Happy to be of help
So, the only problem is that an Item element with both (content + @id)
_and_ @ref attribute is considered valid.
Can't do anything about that. Attribute inter-dependencies are not
supported in XSD.
In my real-world application, I don't manipulate simply Item elements
but there's several complex element types. So that means I need to write
many "dual" element definitions (content through <xsd:group+ actual
type referring to that group). As I'm no expert in XML Schema, would
there be a way to avoid this redundancy ?
Sorry, don't understand that. Could you post an example?

Søren
Aug 23 '06 #4
Soren Kuula wrote:
>So, the only problem is that an Item element with both (content + @id)
_and_ @ref attribute is considered valid.

Can't do anything about that. Attribute inter-dependencies are not
supported in XSD.
Okay.
>In my real-world application, I don't manipulate simply Item elements
but there's several complex element types. So that means I need to
write many "dual" element definitions (content through <xsd:group+
actual type referring to that group). As I'm no expert in XML Schema,
would there be a way to avoid this redundancy ?

Sorry, don't understand that. Could you post an example?
I was referring to the example in my post. For each element type, I need
to define :

* a <xsd:group>
* a <xsd:complexType>, using the previous <xsd:group>

So I was thinking of an XML Schema construct to avoid "leaking"
<xsd:groupdefinitions outside <xsd:complexTypewhere they are used.
No big deal, but that would make the final schema a bit "cleaner".

Cheers,

--
Damiano ALBANI
Aug 25 '06 #5
Damiano ALBANI wrote:
Soren Kuula wrote:
>>So, the only problem is that an Item element with both (content +
@id) _and_ @ref attribute is considered valid.


Can't do anything about that. Attribute inter-dependencies are not
supported in XSD.


Okay.
>>In my real-world application, I don't manipulate simply Item elements
but there's several complex element types. So that means I need to
write many "dual" element definitions (content through <xsd:group+
actual type referring to that group). As I'm no expert in XML Schema,
would there be a way to avoid this redundancy ?


Sorry, don't understand that. Could you post an example?


I was referring to the example in my post. For each element type, I need
to define :

* a <xsd:group>
* a <xsd:complexType>, using the previous <xsd:group>

So I was thinking of an XML Schema construct to avoid "leaking"
<xsd:groupdefinitions outside <xsd:complexTypewhere they are used.
No big deal, but that would make the final schema a bit "cleaner".
Well you don't *have* to use a group when making a complex type. I think
you can always replace a group reference by the content of the referred
group. It's just a sort of macro mechanism.

Søren
Aug 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Michael Strorm | last post by:
Hi! I've been having problems with a DTD. Having had the Sun XML validator reject a document, I put it through 'xmllint' for more information. 'Xmllint' noted a problem with the DTD itself;...
12
by: Jean-Marc Blaise | last post by:
Hi Folks, I'm getting this message with the XML tutorial: getstart_exportXML.cmd file: SQL0444N Routine "DB2XML.CONTENT" (specific name "DB2XMLCONTENTVF") is implemented with code in library...
0
by: Brett | last post by:
I have an XML file that is the documentation for an application. Text log files are in a different location than the XML file. For example: c:\adir\errorlog.txt c:\bdir\doc.xml The VB.NET...
0
by: J.Edwards | last post by:
I'm getting this error when trying to use a control built in VS 2003 (1.1) in a new asp project in VS 2005. "Content controls can only be used in a content page" The control has always worked...
0
by: Phil | last post by:
I am writing an application (using Visual Studio 2003) that consumes a third party Web Service, but I receive the following error : Client found response content type of 'application/xml;...
6
by: Lord0 | last post by:
Hi there, How do I define in a schema that an element (<element>) may have any content i.e. text, other elements, partial elements, angle brackets etc? So all of the following would be valid:...
1
by: dave8421 | last post by:
Hi, I'm trying to make sense of the definition for "Rendered Content" in current CR for CSS 2.1 Is rendered content what is displayed on the particular media or device? from the...
4
by: dmvsatyakumar | last post by:
Hi Alll, When i try to parse the string.xml which is in UTF-16LE, its working fine with JDK 1.4 but gives the following error in JDK 1.5. Error : "Content is not allowed in prolog". Can any one of...
3
by: Alexander Smirnov | last post by:
I'm developing asp.net 2 web application and need to make a custom http handler which sometime must send response with "204 No Content" code. I set HttpResponse.Status="204 No Content"; But asp...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.