Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xml-dev] Schemas and mixed content with Relax NG and W3C XML Schema

From: "Andrew Welch" <andrew.j.welch@-----.--->
To: "Philippe Poulard" <philippe.poulard@------.-----.-->
Date: 7/16/2008 3:55:00 PM
(replying on-list this time)

> I know that with DTDs, when a text is allowed with elements, the best we can
> do is to allow it everywhere between other elements that can be repeated at
> any place in the text :
>
> <!ELEMENT p (#PCDATA|a|ul|b|i|em)*>
>
> unfortunately, we can't enforce the text to be at a given place :
>
> <person>Mr <firstname>John</firstname><lastname>Doe</lastname></person>
>
> the following DTD is invalid, but explain what we'd like to have :
> <!ELEMENT person (#PCDATA,firstname,lastname)>

How about (xsd 1.1):

<xs:complexType name="person" mixed="true">
 <xs:sequence>
   <xs:element ref="firstname"/>
   <xs:element ref="lastname"/>
 </xs:sequence>
 <xs:assert test="text() eq node()[1]"/>
</xs:complexType>

...which should check that the only text() node is the first child.

I guess you could also do:

<xs:assert test="not(text() >> firstname)"/>

to make sure there are no text() nodes after the firstname element...

If you wanted to enforce the positions of the text nodes you could do:

<xs:assert test="text()[1] is node()[1]"/>
<xs:assert test="text()[2] is node()[3]"/>

etc



-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent