Re: [xsl] XML-Schema (W3C) mailing list?

Subject: Re: [xsl] XML-Schema (W3C) mailing list?
From: Wolfgang Laun <wolfgang.laun@xxxxxxxxx>
Date: Fri, 24 Dec 2010 08:05:39 +0100
You could ask questions such as this one on the JAXB user list
http://java.net/projects/jaxb/lists/  users@xxxxxxxxxxxxx or on
http://www.codesynthesis.com/mailman/listinfo/xsd-users

Since I'm going to mention XSLT in answering your question, I might as
well provide an answer here ;-)

The short answer is simple: XML Schema driven parsing of XML documents
depends on element names, not even on present or absent attribute
names, and certainly not at all on attribute values. Values may be
checked by validation against an XML Schema, but there is no way of
expressing that children must have  @type="x" iff parent has
@type="x".

It's easy to write an XSLT stylesheet doing this check.

It's also not difficult to write a transformation converting the
original XML to a well structured one (according to one of your
ideas), and then you can write an XML schema which is capable of
generating Java or C++ code for typesafe unmarshalling.

Or you disregard the dependencies; write the XML schema based on the
original structure and do the (simple) check after unmarshalling.

HTH
-W

On 24 December 2010 06:17, Dietrich Bollmann <diresu@xxxxxx> wrote:
>
> Hi,
>
> Is there a mailing list for asking questions concerning the usage of
> XML-Schemata (W3C) ?
>
> Thanks,
>
> Dietrich
>
>
> PS: For any case, I append the question I would like to ask:
>
> ---
> Subject:  Is there a way to control child element selection depending on
> some parent attribute value?
>
> Hi,
>
> I was asked to implement an XML-Schema
> for a sequence made from
>
>  <list type="a"></list>
>  <list type="b"></list>
>
> in any order, for example
>
>  <sequence>
>    <list type="a"></list>
>    <list type="b"></list>
>    <list type="b"></list>
>    <list type="a"></list>
>    <list type="b"></list>
>    ...
>  </sequence>
>
> each list looking like the following:
>
>  <list type="a">
>    <item type="a"></item>
>    <item type="a"></item>
>    <item type="a"></item>
>    ...
>  </list>
>
> or
>
>  <list type="b">
>    <item type="b"></item>
>    <item type="b"></item>
>    <item type="b"></item>
>    ...
>  </list>
>
> I suppose a better way to implement this would be by rather using
> elements like:
>
>  <aList></aList>
>  <bList></bList>
>
> together with
>
>  <aList>
>    <item type="a"></item>
>    <item type="a"></item>
>    <item type="a"></item>
>    ...
>  </aList>
>
> and
>
>  <bList>
>    <item type="b"></item>
>    <item type="b"></item>
>    <item type="b"></item>
>    ...
>  </bList>
>
> or even
>
>  <aList>
>    <aItem></aItem>
>    <aItem></aItem>
>    <aItem></aItem>
>    ...
>  </aList>
>
> and
>
>  <bList>
>    <bItem></bItem>
>    <bItem></bItem>
>    <bItem></bItem>
>    ...
>  </bList>
>
> But unfortunately I don't control the source XML files...
>
> The latter is easy to implement:
>
>    <xs:element name="sequence">
>      <xs:complexType>
>        <xs:choice maxOccurs="unbounded">
>          <xs:element name="aList" type="aItemList"/>
>          <xs:element name="bList" type="bItemList"/>
>        </xs:choice>
>      </xs:complexType>
>    </xs:element>
>
> but when trying to implement the original proposal with something like:
>
>    <xs:element name="sequence">
>      <xs:complexType>
>        <xs:choice maxOccurs="unbounded">
>          <xs:element name="list">
>            <xs:complexType>
>              <xs:attribute name="type" use="required">
>                <xs:simpleType>
>                  <xs:restriction base="xs:string">
>                    <xs:enumeration value="a"/>
>                  </xs:restriction>
>                </xs:simpleType>
>              </xs:attribute>
>            </xs:complexType>
>          </xs:element>
>          <xs:element name="list">
>            <xs:complexType>
>              <xs:attribute name="type" use="required">
>                <xs:simpleType>
>                  <xs:restriction base="xs:string">
>                    <xs:enumeration value="b"/>
>                  </xs:restriction>
>                </xs:simpleType>
>              </xs:attribute>
>            </xs:complexType>
>          </xs:element>
>        </xs:choice>
>      </xs:complexType>
>    </xs:element>
>
> --- both alternatives are using the same element name "list" and only
> differ concerning the allowed values of attribute "type": "a" in the
> first case, "b" in the latter one --- the schema parser always takes the
> first alternative and complaints about the value of the "type" attribute
> when not corresponding to the one specified in the first alternative...
>
> When on the other side allowing both values --- "a" as well as "b" ---
> for the "type" attribute of the "list" element
>
>    <xs:element name="foo">
>      <xs:complexType>
>        <xs:sequence>
>          <xs:element name="list" maxOccurs="unbounded">
>            <xs:complexType>
>              <xs:attribute name="type" use="required">
>                <xs:simpleType>
>                  <xs:restriction base="xs:string">
>                    <xs:enumeration value="a"/>
>                    <xs:enumeration value="b"/>
>                  </xs:restriction>
>                </xs:simpleType>
>              </xs:attribute>
>            </xs:complexType>
>          </xs:element>
>        </xs:sequence>
>      </xs:complexType>
>    </xs:element>
>
> there seems to be no way to control the "type" value of the "item"
> elements inside the "list" in order to make them match the one of the
> "list" parent element.  The result is, that the whole approach to
> control the elements via the "type" attribute doesn't work at all...
>
> I think this is an implementation decision, as the implementation of a
> parser with some king of backtracking or looking forward mechanism would
> be much less efficient than one which is based on the supposition, that
> all alternative inside of <xs:choice/> have different names and solely
> decides based on this criteria.
>
> Still, as I don't control the source documents, I wonder, if there is
> some way to implement this kind of restriction using XML Schema...
>
> Thanks for the help,
>
> Dietrich

Current Thread