XML Schema Problem

XML Schema Problem

Post by Andy Brow » Fri, 14 Jun 2002 10:21:52



I'm trying to represent the following DTD in XML Schema. I'm getting a UPA
(Unique Particle Attribution) violation on validation of the schema. Can
anyone suggest a way to represent this properly where an schema validator
won't choke?

The DTD >>>>>>

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT test (a,((b|c)*|(d|c)*)) >
<!ELEMENT a EMPTY>
<!ELEMENT b EMPTY>
<!ELEMENT c EMPTY>
<!ELEMENT d EMPTY>

The Schema equivalent is:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
 <xs:element name="a">
  <xs:complexType/>
 </xs:element>
 <xs:element name="b">
  <xs:complexType/>
 </xs:element>
 <xs:element name="c">
  <xs:complexType/>
 </xs:element>
 <xs:element name="d">
  <xs:complexType/>
 </xs:element>
 <xs:element name="test">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="a"/>
    <xs:choice>
     <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="b"/>
      <xs:element ref="c"/>
     </xs:choice>
     <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="d"/>
      <xs:element ref="c"/>
     </xs:choice>
    </xs:choice>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
</xs:schema>

This one rare time when DTDs are better than schema. I hope schema doesn't
remain this strict.

Thanks,
Andy Brown

 
 
 

XML Schema Problem

Post by Marjolein Katsm » Fri, 14 Jun 2002 13:37:00



Quote:> I'm trying to represent the following DTD in XML Schema. I'm getting a
> UPA (Unique Particle Attribution) violation on validation of the
> schema. Can anyone suggest a way to represent this properly where an
> schema validator won't choke?

What are you validating with? I tried with XML Spy (which uses MSXML) and
it tells me the schema is valid.

--
Marjolein Katsma
* Help with HomeSite/Studio: http://hshelp.com/
* Books for webmasters and webrookies: http://books.hshelp.com/

 
 
 

XML Schema Problem

Post by Richard Tob » Fri, 14 Jun 2002 20:43:46




>I'm trying to represent the following DTD in XML Schema. I'm getting a UPA
>(Unique Particle Attribution) violation on validation of the schema.

The DTD is broken for the same reason - the content model for test is
not deterministic.  Suppose you have <test><a/><c/>..., which c does it
match in the content model?

Which of (b|c)* or (d|c)* you have can't be determined until the first
b or d, so you need something like:

  <!ELEMENT test (a,c*,((b,(b|c)*)|(d,(d|c)*))?)>

The corresponding schema will also be legal.

Quote:>This one rare time when DTDs are better than schema.

No, you just don't have a good enough DTD validator to report the error!

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!

 
 
 

XML Schema Problem

Post by Andy Brow » Sat, 15 Jun 2002 04:19:49


Actually, that's the thing... I thought it was valid because XML Spy
validated it. I'm experimenting with Ipedo's XML server, and that gave me
the error.

-Andy



> > I'm trying to represent the following DTD in XML Schema. I'm getting a
> > UPA (Unique Particle Attribution) violation on validation of the
> > schema. Can anyone suggest a way to represent this properly where an
> > schema validator won't choke?

> What are you validating with? I tried with XML Spy (which uses MSXML) and
> it tells me the schema is valid.

> --
> Marjolein Katsma
> * Help with HomeSite/Studio: http://hshelp.com/
> * Books for webmasters and webrookies: http://books.hshelp.com/

 
 
 

XML Schema Problem

Post by Andy Brow » Sat, 15 Jun 2002 04:28:54


I guess that is my problem. I need to have this pattern for the decendants
of test:

* a (this is always the first element)
* the second element, after the 'a' element, may be 'c', 'b', or 'd'
* the third element may be 'c', 'b' (only if 'd' has not been previously
selected), or 'd' (only if 'b' has not been previously selected)
* the fourth element may be 'c', 'b' (only if 'd' has not been previously
selected), or 'd' (only if 'b' has not been previously selected)
* the Xth element may be 'c', 'b' (only if 'd' has not been previously
selected), or 'd' (only if 'b' has not been previously selected)

Any thoughts on how to represent this? Your previous example dictates that
'c' must appear immediately after 'a' or else 'b' or 'd' cannot appear.

Thanks for your input.

-Andy




> >I'm trying to represent the following DTD in XML Schema. I'm getting a
UPA
> >(Unique Particle Attribution) violation on validation of the schema.

> The DTD is broken for the same reason - the content model for test is
> not deterministic.  Suppose you have <test><a/><c/>..., which c does it
> match in the content model?

> Which of (b|c)* or (d|c)* you have can't be determined until the first
> b or d, so you need something like:

>   <!ELEMENT test (a,c*,((b,(b|c)*)|(d,(d|c)*))?)>

> The corresponding schema will also be legal.

> >This one rare time when DTDs are better than schema.

> No, you just don't have a good enough DTD validator to report the error!

> -- Richard
> --
> Spam filter: to mail me from a .com/.net site, put my surname in the
headers.

> FreeBSD rules!

 
 
 

XML Schema Problem

Post by Richard Tob » Sat, 15 Jun 2002 06:15:59




>Any thoughts on how to represent this? Your previous example dictates that
>'c' must appear immediately after 'a' or else 'b' or 'd' cannot appear.

I think my content model does what you want:

Quote:>>   <!ELEMENT test (a,c*,((b,(b|c)*)|(d,(d|c)*))?)>

It allows a, zero-or-more c, then (optionally) either b or d followed
by a mixture of c and whichever of b and d it was.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!

 
 
 

XML Schema Problem

Post by Andy Brow » Sat, 15 Jun 2002 09:26:04


It works ... with the exception of 'c' being the only element allowed after
'a'. I'd like to allow either b, c, or d after a.

Maybe <!ELEMENT test (a, (c*|(b|c)*|(d|c)*))/>... I'm tryin this next.

Thanks,
Andy




> >Any thoughts on how to represent this? Your previous example dictates
that
> >'c' must appear immediately after 'a' or else 'b' or 'd' cannot appear.

> I think my content model does what you want:

> >>   <!ELEMENT test (a,c*,((b,(b|c)*)|(d,(d|c)*))?)>

> It allows a, zero-or-more c, then (optionally) either b or d followed
> by a mixture of c and whichever of b and d it was.

> -- Richard
> --
> Spam filter: to mail me from a .com/.net site, put my surname in the
headers.

> FreeBSD rules!

 
 
 

XML Schema Problem

Post by Marjolein Katsm » Sat, 15 Jun 2002 17:04:15



Quote:> Actually, that's the thing... I thought it was valid because XML Spy
> validated it. I'm experimenting with Ipedo's XML server, and that gave
> me the error.

Thanks, good to know that XML Spy (or MSXML) doesn't catch everything
there is to catch ... still evaluating it, but I'll probably buy it
anyway. While there's a few things I don't like, I do find a lot to
like.

--
Marjolein Katsma
* Help with HomeSite/Studio: http://hshelp.com/
* Books for webmasters and webrookies: http://books.hshelp.com/

 
 
 

XML Schema Problem

Post by Richard Tob » Sat, 15 Jun 2002 20:03:06




>It works ... with the exception of 'c' being the only element allowed after
>'a'.
>> >>   <!ELEMENT test (a,c*,((b,(b|c)*)|(d,(d|c)*))?)>

No, it allows b or c or d.  The first c has a star, so it is optional.

Do you mean some XML parser rejects, say,

  <test><a/><d/></test>

?  If so, it's faulty.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!