Page 1 of 1

enumeration

Posted: Sun Mar 20, 2011 8:12 pm
by plebel
I'm an XML newbie! So I appreciate any help you can give me.

I want to know if there's a way to populate an attribute enumeration
from a list - perhaps from a "keyref"? from some other element.

Pierre

Re: enumeration

Posted: Wed Mar 23, 2011 10:43 am
by sorin_ristache
Hello,

An attribute value can be an enumeration of values that are extracted from other element. Can you give more details about the problem, maybe an example of an attribute and the location of the enumeration of values that you need to put in the attribute?


Regards,
Sorin

Re: enumeration

Posted: Wed Mar 23, 2011 5:02 pm
by plebel
Sorin, thanks for your interest,
here's an example where I would want the enumeration for the attribute "Atype_Name" to contain a list of what the user has input for "NameA":

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Base">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="A">
<xs:complexType>
<xs:attribute name="NameA" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="B">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Atype">
<xs:complexType>
<xs:attribute name="Atype_Name">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="ChooseAnames"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="NameB"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Re: enumeration

Posted: Mon Apr 04, 2011 12:31 pm
by sorin_ristache
Do you want to restrict the values that the user is allowed to enter as value for the NameA attribute and keep a list of the values entered by the user in the Atype_Name attribute? In this case you should have a schema like the following. Otherwise please give an example of XML document that is valid and another one that is invalid.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Base">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="A">
<xs:complexType>
<xs:attribute name="NameA" type="EnumerationOfNames"/>
</xs:complexType>
</xs:element>
<xs:element maxOccurs="unbounded" name="B">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Atype">
<xs:complexType>
<xs:attribute name="Atype_Name">
<xs:simpleType>
<xs:list itemType="EnumerationOfNames"/>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="NameB"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:simpleType name="EnumerationOfNames">
<xs:restriction base="xs:string">
<xs:enumeration value="allowed_value_1"/>
<xs:enumeration value="allowed_value_2"/>
<xs:enumeration value="allowed_value_3"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>

Regards,
Sorin

Re: enumeration

Posted: Tue Apr 05, 2011 11:59 pm
by plebel
Soren,
thanks for looking at this.
I didn't want to restrict the contents of NameA.
I did want to restrict the contents of "Atype_Name" to any of the values that actually got used for the NameA.

Re: enumeration

Posted: Wed Apr 06, 2011 10:37 am
by sorin_ristache
plebel wrote:I did want to restrict the contents of "Atype_Name" to any of the values that actually got used for the NameA.
Please give one or two examples of valid and invalid XML documents for the restriction that you want to encode in the XML Schema.

If you to set some values in a restriction in an XML Schema you have to know/decide these values in advance, before creating any XML instance documents for that schema. If you want to allow in "Atype_Name" any value that is used in "NameA" what is it that you want to restrict? I think some examples of XML documents will clarify that. Let's start from a few examples of XML instance documents and based on them we can create an XML Schema that can validate such XML documents.


Regards,
Sorin