Simple XML Schema validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hitch4hike
    New Member
    • May 2007
    • 2

    Simple XML Schema validation

    I am relatively new to XML Schema and have a question about validation. I want to create a Schema to validate a huge customer XML files that we get. I do not have control over the entire XML document, but there are some specific elements I want to validate.

    For eg. In the XML document, I want to validate all <Customer> elements, and within <Customer> element I want to make sure there is a couple of important elements: <Name>, <Age>, <City>, <ZipCode>. I do not care about any other elements, text, attributes etc under <Customer>. It seems to me that schema is very heavy weight and does not give me flexibility to specify only required elements.

    Please let me know your thoughts.
  • dorinbogdan
    Recognized Expert Contributor
    • Feb 2007
    • 839

    #2
    Welcome to TheScripts TSDN....

    It seems not very complicate.
    I'd recommend to take a look at this easy XSD tutorial. It will answer better your questions in about 30 min.

    Dorin.

    Comment

    • hitch4hike
      New Member
      • May 2007
      • 2

      #3
      Thanks for your response. I have tried various options under Schema and it seems to me that I cannot express my requirement with Schema. I would like to validate my understanding.

      I am interested in validating an element that has a set of sub elements:

      Eg. element <Top> "must" have one occurrance of elements <a>, <b>, <c>, <d>. I do not want any other restriction on <Top> ie)

      <Top><fish><a/><car><b/><c/><car><d/><Top>
      <Top><fish><c/><motor><b/><a/><car><d/><Top>
      <Top><fish><c/><motor><d/><a/><car><b/><Top>
      ...
      ...

      All these are valid. <a>, <b>, <c>, <d> must be child elements of <Top> in any order. And <Top> can have any other elements.

      I do not see a way to express this under XSchema. Please let me know if I am missing something

      Comment

      • dorinbogdan
        Recognized Expert Contributor
        • Feb 2007
        • 839

        #4
        Please try yourself to write and play with a schema, and then come back for further help.
        We will not write full source code, this is against site rules.
        But we'll give suggestions and small code snippets whenever is possible.

        Thanks,
        Dorin.

        Comment

        Working...