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. XML Schema and circular references

XML Schema and circular references

Scheduled Pinned Locked Moved XML / XSL
xmlquestioncsharpasp-netdatabase
3 Posts 2 Posters 10 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.
  • S Offline
    S Offline
    Senkwe Chanda
    wrote on last edited by
    #1

    Clearly I'm relatively new to authoring xml documents. If I have an elment eg CarEngineCompnent and this element can have more CarEngineComponent within it, how do I represent this in an XML Schema? I'm confused as to what the schema should look like. ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff

    E 1 Reply Last reply
    0
    • S Senkwe Chanda

      Clearly I'm relatively new to authoring xml documents. If I have an elment eg CarEngineCompnent and this element can have more CarEngineComponent within it, how do I represent this in an XML Schema? I'm confused as to what the schema should look like. ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff

      E Offline
      E Offline
      Erik Westermann
      wrote on last edited by
      #2

      Senkwe Chanda wrote: how do I represent this in an XML Schema? ...like this:

      <?xml version="1.0" encoding="UTF-8"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:element name="CarEngineComponent">
      <xs:complexType mixed="true">
      <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element ref="CarEngineComponent"/>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xs:schema>

      Although technically allowed, having a structure like this undermines one of the the benefits that an XSD (XML Schema) provides, namely, strong types. What this schema essentially says is that a CarEngineComponent is a mixed type element that can contain a value and another element. Although there's noting wrong with that from a purely structural point of view, most XML documents don't use that structure prefering instead ot have elements that contain data or other elements. A bettter structure could be to have <CarEngineComponents> (note the plural form of the word) that contain one or more <CarEngineComponent> types. The naming convention makes it clear that <CarEngineComponents> is a container for something else. Erik Westermann Author, Learn XML In A Weekend (October 2002)

      S 1 Reply Last reply
      0
      • E Erik Westermann

        Senkwe Chanda wrote: how do I represent this in an XML Schema? ...like this:

        <?xml version="1.0" encoding="UTF-8"?>
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
        <xs:element name="CarEngineComponent">
        <xs:complexType mixed="true">
        <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element ref="CarEngineComponent"/>
        </xs:choice>
        </xs:complexType>
        </xs:element>
        </xs:schema>

        Although technically allowed, having a structure like this undermines one of the the benefits that an XSD (XML Schema) provides, namely, strong types. What this schema essentially says is that a CarEngineComponent is a mixed type element that can contain a value and another element. Although there's noting wrong with that from a purely structural point of view, most XML documents don't use that structure prefering instead ot have elements that contain data or other elements. A bettter structure could be to have <CarEngineComponents> (note the plural form of the word) that contain one or more <CarEngineComponent> types. The naming convention makes it clear that <CarEngineComponents> is a container for something else. Erik Westermann Author, Learn XML In A Weekend (October 2002)

        S Offline
        S Offline
        Senkwe Chanda
        wrote on last edited by
        #3

        Thanks Erik. I'm trying to setup a schema for a situation where the level of containment is unknown and/or variable. For example, that CarEngineComponent could have a CarEngineComponent that itself contains another CarEngineComponent. I'm getting the feeling that perhaps I'm not thinking in an XML-like way (which I've surprisingly found is not as sraight forward as I'd thought) Thanks again, I'll go and rethink my document. Regards Senkwe ASP.NET can never fail as working with it is like fitting bras to supermodels - it's one pleasure after the next - David Wulff

        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