Announcement

Collapse
No announcement yet.

Choice mit Begrenzung einzelner Elemente

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Choice mit Begrenzung einzelner Elemente

    Hallo,

    ich will folgendes realisieren:

    Dabei sollen die Elemente Node1 bis 3 bis zu 20x in dem Knoten nodes in beliebiger Reihenfolge vorkommen.

    Jedoch musste ich feststellen, dass die Limitierung einzelner Elemente auf max 1x Vorkommen nicht funktioniert.

    HTML Code:
    <nodes>
    	<node1 value="test1" />
    	<node2 value="test2" />
    	<node2 value="test2" />
    	<node2 value="test2" />
    	<node2 value="test2" />
    	<node3 value="test3" />
    </nodes>
    XSD file:

    HTML Code:
    <xsd:element name="nodes" type="nodes-type" />
    
    <xsd:complexType name="nodes-type">
     <xsd:choice maxOccurs="20">
      <xsd:element name="node1" type="node-type" />
      <xsd:element name="node2" type="node-type" />
      <xsd:element name="node3" type="node-type" />
     </xsd:choice>
    </xsd:complexType>
    
    <xsd:complexType name="node-type">
      <xsd:attribute name="value" type="xsd:string" />
    </xsd:complexType>
    Ich habe versucht, ein einzelnes Element im choice Tag mit maxOccurs zu limitieren, allerdings hat dieses, sofern im Choice schon ein maxOccurs steht keinen Einfluss mehr.
    Soweit soll das Element node2 immer noch 20x vorkommen dürfen.

    HTML Code:
    ...
    <xsd:element name="node1" type="node-type" maxOccurs="1" />
    ...
    <xsd:element name="node3" type="node-type" maxOccurs="1" />
    ...
    Wie könnte das denn funktionieren?

  • #2
    Möglich ist
    [highlight=xml]
    <xs:element name="nodes">
    <xs:sequence>
    <xs:element name="node1"/>
    <xs:element name="node2" maxOccurs="20"/>
    <xs:element name="node3"/>
    </xs:sequence>
    </xs:element>
    [/highlight]
    Die Reihenfolge node1, node2{1,20}, node3 ist dabei aber festgelegt.

    Comment


    • #3
      Folgendermaßen funktioniert es zwar, aber nur mit simple types.

      Ist es auch möglich, das für complex types zu realisieren?

      HTML Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      	<xs:complexType name="root">
      		<xs:choice minOccurs="1" maxOccurs="3">
      			<xs:element name="node1" type="xs:string"/>
      			<xs:element name="node2" type="xs:string"/>
      			<xs:element name="node3" type="xs:string"/>
      		</xs:choice>
      	</xs:complexType>	
      	<xs:element name="root" type="root">
      		<xs:unique name="choiceID">
      			<xs:selector xpath="."/>
      			<xs:field xpath="node1"/>
      			<xs:field xpath="node2"/>
      			<xs:field xpath="node2"/>
      		</xs:unique>
      	</xs:element>
      </xs:schema>

      Comment

      Working...
      X