Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. XSD validation on recursive XML elements [modified]

XSD validation on recursive XML elements [modified]

Scheduled Pinned Locked Moved XML / XSL
xmldatabasehelpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janBarP
    wrote on last edited by
    #1

    Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007

    S B 2 Replies Last reply
    0
    • J janBarP

      Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007

      S Offline
      S Offline
      Stefan Troschuetz
      wrote on last edited by
      #2

      Not tested, but should be at least a good starting point:

      <?xml version="1.0" encoding="utf-8" ?>
      <xs:schema targetNamespace="http://tempuri.org/XMLSchema.xsd"
      elementFormDefault="qualified"
      xmlns="http://tempuri.org/XMLSchema.xsd"
      xmlns:mstns="http://tempuri.org/XMLSchema.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="link">
      xs:complexType</xs:complexType>
      </xs:element>

      <xs:element name="mid">
      	<xs:complexType></xs:complexType>
      </xs:element>
      
      <xs:element name="bottom">
      	<xs:complexType></xs:complexType>
      </xs:element>
      
      <xs:element name="top">
      	<xs:complexType>
      		<xs:choice>
      			<xs:sequence>
      				<xs:element ref="mstns:bottom"></xs:element>
      			</xs:sequence>
      			<xs:sequence>
      				<xs:choice minOccurs="0" maxOccurs="unbounded">
      					<xs:element ref="mstns:top"></xs:element>
      					<xs:element ref="mstns:link"></xs:element>
      					<xs:element ref="mstns:mid"></xs:element>
      				</xs:choice>
      			</xs:sequence>
      		</xs:choice>
      	</xs:complexType>
      </xs:element>
      

      </xs:sche


      "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

      www.troschuetz.de

      1 Reply Last reply
      0
      • J janBarP

        Hi, I want to create a XSD schema to use for validating XML files like the following: top> top> top> top> /top> link> link> mid> mid> /top> top> bottom> /top> /top> A "top" element can contain any number of "top" elements or any number of "link" elements or any number of "mid" elements. A "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element. A "link" or "mid" or "bottom" element cannot contain any elements. Any advice, please help? -- modified at 2:51 Wednesday 2nd May, 2007

        B Offline
        B Offline
        BoneSoft
        wrote on last edited by
        #3

        Or even simpler...

        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
        <xs:complexType name="top">
        xs:sequence
        <xs:element name="top" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="link" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="mid" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
        <xs:element name="bottom" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
        </xs:sequence>
        </xs:complexType>

        <xs:element name="top" type="top" />
        </xs:schema>


        Try code model generation tools at BoneSoft.com.

        S 1 Reply Last reply
        0
        • B BoneSoft

          Or even simpler...

          <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
          <xs:complexType name="top">
          xs:sequence
          <xs:element name="top" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
          <xs:element name="link" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
          <xs:element name="mid" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
          <xs:element name="bottom" type="xs:string" minOccurs="0" maxOccurs="unbounded" />
          </xs:sequence>
          </xs:complexType>

          <xs:element name="top" type="top" />
          </xs:schema>


          Try code model generation tools at BoneSoft.com.

          S Offline
          S Offline
          Stefan Troschuetz
          wrote on last edited by
          #4

          This doesn't cover the requirements that a "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element.


          "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

          www.troschuetz.de

          B 1 Reply Last reply
          0
          • S Stefan Troschuetz

            This doesn't cover the requirements that a "top" element can contain only one "bottom" element and no other element if it contains a "bottom" element.


            "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook

            www.troschuetz.de

            B Offline
            B Offline
            BoneSoft
            wrote on last edited by
            #5

            True, didn't realize that was a requirement. I guess choice is the only valid approach.


            Try code model generation tools at BoneSoft.com.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups