XML schema help



  • I am going to be getting XML data from an external source and am trying to create a schema for it. The XML will look something like this

    <user>

       <Questions1>

         <field name="name1">value</field>

         <field name="name2">value</field>

         <field name="name3">value</field>

         <field name="name4">value</field>

         <field name="name5">value</field>

       </Questions1>

       <Questions2>

         <field name="name6">value</field>

         <field name="name7">value</field>

         <field name="name8">value</field>

         <field name="name9">value</field>

       </Questions2>

    </user>



    What I would like to have be inforced is the name of the field has a fixed value and the possible values for the field tag limited to only what is possible for the fixed value in the name. So "name1" can only hold the values 1,2 and 3 and "name2" can only hold the values a,b and c.

    If I need to redesign my xml, that's fine. I've gotten the schema so it will limit the values in "Name" and limit the "value" to a value any of the fields but when I try to limit it more, it says I can't have different types for the same field.

    Thanks for any help you can give.



  • I am no expert but you will probably have to redesign the schema. What you are trying to do is have the field tag be multiple tags based on an attribute which seems to be beyond the parser you are using.

    Instead of using <field name="name1"> I would use <field1> or <field1 name="name1"> if you need the name for something else.

     

    Hopefully this helps.



  • Or maybe there should be multiple types of fields?  Most likely there are only a handful of types of fields, with many instances of each.  If each field is truely different, then I don't think enforcing a schema will be useful at all.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.