XSD unordered sequence with undefined elements ignored

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • klikic

    #1

    XSD unordered sequence with undefined elements ignored

    Hi.
    How can create a unordered sequence with defined elements that can
    occur ones and "other" elements that are ignored.
    Example:
    XML:
    <Recur>
    <ignoredElement >saasda</ignoredElement>
    <frequency>sdsa d</frequency>
    <recurEnd>kjdsk dj</recurEnd>
    </Recur>

    Elements "frequency" and "recurEnd" are not optional and can occur only
    ones. Element "ignoredElement " or any other element taht is not
    defined, can occur multiple times or none, and can be at any position
    (between mandatory elements or at end,...).

    I created XSD:
    <xs:element name="Recur">
    <xs:complexTy pe mixed="false">
    <xs:sequence maxOccurs="unbo unded">
    <xs:element ref="frequency"/>
    <xs:element ref="endRecur"/>
    <xs:any namespace="##ot her" minOccurs="0" maxOccurs="unbo unded"//>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    This doesn't work: I have errors while validating XML with XSD.
    I tried with choice but with same effect.
    Any help or suggestion would be nice.
    Thanks.
    Alan

  • klikic

    #2
    Re: XSD unordered sequence with undefined elements ignored

    I am sorry I made a mistake:
    element in XML is not recurEnd but endRecur.
    <Recur>
    <ignoredElement >saasda</ignoredElement>
    <frequency>sdsa d</frequency>
    <recurEnd>kjdsk dj</recurEnd>
    </Recur>

    Comment

    • George Bina

      #3
      Re: XSD unordered sequence with undefined elements ignored

      Hi,

      You cannot do that with XML Schema. All you can do is to relax the
      content model allowing more than what you want, use <xs:choice
      maxOccurs="unbo unded">. If Relax NG does not scare you then look into
      that. Alternatively you can add a couple of Schematron rules inside XML
      Schema to enforce one occurrence of frequency and endRecur elements.
      See below a complete example that uses Schematron embedded rules:

      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      targetNamespace ="http://www.example.com "
      xmlns:t="http://www.example.com ">
      <xs:annotatio n>
      <xs:appinfo>
      <ns xmlns="http://www.ascc.net/xml/schematron"
      uri="http://www.example.com " prefix="t"/>
      </xs:appinfo>
      </xs:annotation>
      <xs:element name="Recur">
      <xs:annotatio n>
      <xs:appinfo>
      <pattern xmlns="http://www.ascc.net/xml/schematron"
      name="test">
      <rule context="t:Recu r">
      <assert test="count(t:f requency)=1">Th ere should be one
      occurrence of frequency.</assert>
      <assert test="count(t:e ndRecur)=1">The re should be one
      occurrence of endRecur.</assert>
      </rule>
      </pattern>
      </xs:appinfo>
      </xs:annotation>
      <xs:complexTy pe mixed="false">
      <xs:choice maxOccurs="unbo unded">
      <xs:element name="frequency " form="qualified "
      type="xs:string "/>
      <xs:element name="endRecur" form="qualified "/>
      <xs:any namespace="##ot her" minOccurs="0" maxOccurs="unbo unded"
      processContents ="lax"/>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xs:schema>

      Best Regards,
      George
      ---------------------------------------------------------------------
      George Cristian Bina
      <oXygen/XML Editor, Schema Editor and XSLT Editor/Debugger


      Comment

      Working...