Groups | Blog | Home
all groups > dotnet xml > april 2006 >

dotnet xml : xsd enumeration



Davidoff
4/27/2006 1:46:34 PM
Hi,

I parse an XML file with a XSD schema.
One XmlNode has an attribute whose type is a restriction of xs:string :

<xs:simpleType name="stypeDay">
<xs:restriction base="xs:string">
<xs:enumeration value="Mon"/>
<xs:enumeration value="Tue"/>
<xs:enumeration value="Wed"/>
<xs:enumeration value="Thur"/>
<xs:enumeration value="Fri"/>
<xs:enumeration value="Sat"/>
<xs:enumeration value="Sun"/>
</xs:restriction>
</xs:simpleType>

Is it possible to read from such an its rank in the enumeration
That is while reading
<Poste Day="Mon">, get 0
<poste Day="Tue">, get 1
and son on...

Thanks

David

Martin Honnen
4/27/2006 2:43:14 PM


[quoted text, click to view]

What are you using to parse the XML, .NET 1.x or .NET 2.0? And what API,
for instance XmlDocument or XmlTextReader, do you use or do you want to use?


--

Martin Honnen --- MVP XML
Davidoff
4/27/2006 3:41:36 PM
Here is the code to load the document according to its schema
txtReader = new XmlTextReader(sXMLFileName);
reader = new XmlValidatingReader(txtReader);
reader.ValidationType = ValidationType.Schema ;
XmlDocument doc = new XmlDocument();
doc.Load(reader);
return(doc.DocumentElement);


Then I parse the XmlDocument under .NET1.0

David
"Martin Honnen" <mahotrash@yahoo.de> a écrit dans le message de news:
e7R8ngfaGHA.4972@TK2MSFTNGP03.phx.gbl...
[quoted text, click to view]

Martin Honnen
4/27/2006 6:59:47 PM


[quoted text, click to view]

With .NET 1.x there is no connection between DOM (XmlDocument, XmlNode)
and schema types. .NET 2.0 changes that, there XmlNode has a property
SchemaInfo.
So with .NET 1.x all you can do is use XmlValidatingReader and access
the SchemaType property
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXmlValidatingReaderClassSchemaTypeTopic.asp>
to read out schema information while the document is being parsed. The
schema object model (SOM) allows you to read out schema information, for
instance the facets of a simple type restriction.


--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button