OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Non-deterministic schema issue....

[ Lists Home | Date Index | Thread Index ]

> This content model is infact invalid. In XML Schema you're
> not allowed to declare
> multiple elements with the same name and type in the same
> content model. This is

Actually, you are allowed to have two element declarations with the same
name in the same content model, provided that they have the same type.  In
this case, they have different types, rendering it invalid.

Even if they did have the same type, though, it is also invalid because it
is non-deterministic.  The third element declaration has minOccurs="0", so
if you encountered a "characteristic" element as the third element, you
would not know if it matched the third or fourth declaration.

Using your other example, I would recommend the following approach:

> > > <library>
> > >     <journal>...</journal>
> > >     <journal>...</journal>
> > >     <hardback>...</hardback>
> > >     <book>...</book>
> > >     <book>...</book>
> > > </library>

Or, as Eddie said, you could define types named "journal", "hardback",
"book", etc. and have them all inherit from an abstract "publicationType".
Then use type substitution via xsi:type to indicate in the instance what
type they are.

> > > <library>
> > >     <publication xsi:type="journal">...</publication>
> > >     <publication xsi:type="journal">...</publication>
> > >     <publication xsi:type="hardback"/>...</publication>
> > >     <publication xsi:type="book"/>...</publication>
> > >     <publication xsi:type="book"/>...</publication>
> > > </library>

Hope that helps,
Priscilla

------------------------------------------------------------------
Priscilla Walmsley                          priscilla@walmsley.com
Vitria Technology                            http://www.vitria.com
Author, Definitive XML Schema                  (Prentice Hall PTR)
------------------------------------------------------------------

> -----Original Message-----
> From: Eddie Robertsson [mailto:eddie@allette.com.au]
> Sent: Wednesday, January 30, 2002 5:34 PM
> To: andrzej@chaeron.com
> Cc: xml-dev@lists.xml.org
> Subject: Re: [xml-dev] Non-deterministic schema issue....
>
>
> Hi,
>
> > This exchange came up on a different newsgroup.  Anyone
> > know what the correct answer is?
> >
> > > > > MSXML4 is complaining about the schema below, saying
> that it is
> > > > > non-deterministic - i cant work out precisely why.
> > > >
> > > > >       <xsd:sequence>
> > > > >        <xsd:element name="characteristic" type="chartype1"
> > > > > maxOccurs="unbounded"/>
> > > > >        <xsd:element name="characteristic" type="chartype2"
> > > > > maxOccurs="unbounded"/>
> > > > >        <xsd:element name="characteristic"
> type="chartype3" minOccurs="0"
> > > > > maxOccurs="unbounded"/>
> > > > >        <xsd:element name="characteristic" type="chartype4"
> > > > > maxOccurs="unbounded"/>
> > > > >       </xsd:sequence>
> > > >
>
> This content model is infact invalid. In XML Schema you're
> not allowed to declare
> multiple elements with the same name and type in the same
> content model. This is
> the reason for MSXML4's error message. If the different types
> can be derived from
> a common base type you can solve this by using the xsi:type
> [1] attribute in the
> instance document but otherwise you have to declare the
> elements with different
> names.
>
> Cheers,
> /Eddie
>
> [1] http://www.w3.org/TR/xmlschema-0/#UseDerivInInstDocs
>
> >
> > > > The problem is probably because of the minOccurs=0 on the third
> > > > element.  There is no way to know if the third element in such a
> > > > sequence is of type 3 or 4 without doing a read-ahead
> of it's child
> > > > elements.  I don't think that Parsers read-ahead typically.
> > >
> > > But the minOccurs shouldnt be causing a problem. For
> starters, if we get rid
> > > of the minOccurs, the parser still complains. Are you
> saying that a schema
> > > enforcing the instance below would be non-deterministic
> because all the
> > > elements in the sequence have the same name?
> > >
> > > <library>
> > >     <publication type="journal">...</publication>
> > >     <publication type="journal">...</publication>
> > >     <publication type="journal">...</publication>
> > >     <publication type="hardback"/>...</publication>
> > >     <publication type="book"/>...</publication>
> > >     <publication type="book"/>...</publication>
> > >     <publication type="book"/>...</publication>
> > >     <publication type="book"/>...</publication>
> > >     <publication type="reference"/>...</publication>
> > >     <publication type="misc"/>...</publication>
> > >     <publication type="misc"/>...</publication>
> > > </library>
> > >
> > >
> > > How else do you get around this? Giving each element a
> unique name would be
> > > a little silly, especially when there could be hundreds
> of them. besides..
> > > if you then wanted to transform the XML into some HTML
> (as i do).. it would
> > > be much trickier.
> >
> > Andrzej Jan Taramina
> > Chaeron Corporation: Enterprise System Solutions
> > http://www.chaeron.com
> >
> > -----------------------------------------------------------------
> > The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> > initiative of OASIS <http://www.oasis-open.org>
> >
> > The list archives are at http://lists.xml.org/archives/xml-dev/
> >
> > To subscribe or unsubscribe from this list use the subscription
> > manager: <http://lists.xml.org/ob/adm.pl>
>
>
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
>
> The list archives are at http://lists.xml.org/archives/xml-dev/
>
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
>
>





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS