views:

27

answers:

2

I am not a programmer, so this may or may not make sense, but I would like to be able to link an external data file to an XSD file to specify whether a user belongs to a certain group.

Without linking, the code currently stands as:

<xs:element name="user">
    <xs:simpleType>
      <xs:restriction base="xs:string">
          <xs:enumeration value="user1">
          <xs:enumeration value="user2">
          <xs:enumeration value="user3">
      </xs:restriction>
   </xs:simpleType>
</xs:element>

When an XML file is created from this, a user must be from one of the values listed.

Instead of listing the various enumeration values in the XSD file, I would like to link to an external file that can be be easily updated to add allowable users to the XSD file.

A: 

This is not possible in XML Schema. The choice is between enumeration inside the schema (but then it's hard to add values) or writing additional external validation code (but then you have code to write).

xcut
I am not against writing more code and at some point we are going to be getting a programmer for this project. What type of code are you referring to when you talk about external validation?
thecraic
You have some choices there. Either you use something like Schematron, or you have to write it yourself in Java (e.g. by loading the XML documents using JAXB)
xcut
Thank you for your help, I will look into those.
thecraic
A: 

Could you explain how the schema is being used? That may help in finding a good solution for you.

But the xcut is right, the general answer is that what you're asking for can't be done. Except of course by pasting

 <xs:enumeration value="user4">

into the schema when you have a new user, which is actually pretty easy...

Gabriel
I think what I was thinking of doing would be best handled using some type of Java programming (most likely JAXB, which xcut mentioned).Obviously, pasting in the enumeration values would add new users, but I was hoping to set one value which would be determined by an external file which had a list of possible users.The hope in the long run, would be to keep the XSD file as static as possible and only change the external file/files to add/remove users to various permissions levels. Admin/Guest/etc.
thecraic
That's actually really easy to do... just define the simpleType as it's own named type in a separate schema (as opposed to the anonymous type it is above). This schema will be your external user file. Then in your main schema, import the user one and just reference that simpleType. So you have the users in a separate file, it's just that the syntax will be in XSD format, but that shouldn't be too big of a deal.
Gabriel