xsd - xml schema - single and multi element occurrence -


I have an XML schema inside the "Video" element and "YouTube" element:

 < Code> & lt; Xs: element name = "video" & gt; & Lt; XS: complexType & gt; & Lt; XS: Sequence & gt; & Lt; Xs: element ref = "youtube" minOccurs = "0" maxOccurs = "1" /> & Lt; / XS: sequence & gt; & Lt; Xs: attribute name = "file" type = "x: string" /> & Lt; / XS: complexType & gt; & Lt; / XS: element & gt;   

And I want to add the available video types to another element "Ultimate":

  & lt; Xs: element name = "param" & gt; & Lt; XS: complexType & gt; & Lt; Xs: attribute name = "name" type = "x: string" = "required" /> & Lt; Xs: attribute name = "value" type = "x: string" = "required" /> & Lt; / XS: complexType & gt; & Lt; / XS: element & gt;   

I will have the "ultimate" element next to "YouTube".

restriction:

  • YouTube can be only once in my XML
  • Ultimate - my XML may be multiple times

    By the way:

      & lt; Video & gt; & Lt; Youtube file = "aaa" /> & Lt; Param name = "a1" value "b1" /> & Lt; Param name = "a2" value "b2" /> & Lt; / Video & gt;   

    How does this restriction maintain in this schema?

    If I do something like this:

      & lt; Xs: sequence & gt; & Lt; Xs: element ref = "youtube" minOccurs = "0" maxOccurs = "1" /> & Lt; Xs: element reserved = "ultimate" minOccurs = "0" maxOccurs = "unbounded" /> & Lt; / XS: sequence & gt;   

    If the sequence is specified like this

       & Lt; Xs: element reserved = "ultimate" minOccurs = "0" maxOccurs = "unbounded" /> & Lt; / XS: sequence & gt;   

    It determines that the ultimate should be after YouTube - but I do not want to specify the order

    Here is the XSD schema:

       & Lt; Xs: element reserved = "ultimate" minOccurs = "1" maxOccurs = "unbounded" /> & Lt; / XS: Options & gt; & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; Xs: element name = "youtube" & gt; & Lt; XS: complexType & gt; & Lt; Xs: attribute name = "file" type = "x: string" = "required" /> & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; Xs: element name = "param" & gt; & Lt; XS: complexType & gt; & Lt; Xs: attribute name = "name" type = "x: string" = "required" /> & Lt; Xs: attribute name = "value" type = "x: string" = "required" /> & Lt; / XS: complexType & gt; & Lt; / XS: element & gt; & Lt; / XS: Schema & gt;   

    Example (well-formed and valid) XML:

      & lt ;? XML version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Video & gt; & Lt; Youtube file = "aaa" /> & Lt; Param name = "a1" value = "b1" /> & Lt; Param name = "a2" value = "b2" /> & Lt; / Video & gt;   

    The above solution is an issue with xs: option allows two YouTube elements xs: all element, which Resolve, but unfortunately, it is impossible to get the maximum oxx of more than one (xs: all borders).

    In other words, there is no 100% solution using XML Schema 1.0. If not above enough then you can use other schema language such as relx ng or skiometron.

    Edit:

    You can type video elements in XML Schema 1.1 (Superset of XML Schema 1.0) such as:

       & Lt; Xs: element reserved = "ultimate" minOccurs = "0" maxOccurs = "unbounded" /> & Lt; / XS: All & gt; & Lt; / XS: complexType & gt; & Lt; / XS: element & gt;    

Comments