Hi J
You use the classes in the System.Xml.Sche ma namespace to do this. Here's
some (inefficient!) code that shows how to read through a document, and test
whether the element can have an attribute called "id"...
HTH
Nigel Armstrong
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim t As New System.Xml.XmlT extReader("C:\t esta.xml")
Dim v As New System.Xml.XmlV alidatingReader (t)
v.ValidationTyp e = Xml.ValidationT ype.Schema
AddHandler v.ValidationEve ntHandler, AddressOf VEH
Dim som As System.Xml.Sche ma.XmlSchema =
System.Xml.Sche ma.XmlSchema.Re ad(New IO.FileStream(" C:\test.xsd",
IO.FileMode.Ope n), AddressOf VEH)
som.Compile(Add ressOf VEH)
While v.Read
If v.NodeType = Xml.XmlNodeType .Element Then
Dim oc As System.Xml.Sche ma.XmlSchemaObj ectCollection =
som.Items
For Each o As Object In oc
If TypeOf o Is System.Xml.Sche ma.XmlSchemaEle ment Then
If o.Name = v.Name Then
Dim ct As System.Xml.Sche ma.XmlSchemaCom plexType
= o.SchemaType
For Each a As
System.Xml.Sche ma.XmlSchemaAtt ribute In ct.Attributes
If a.Name = "id" Then
MessageBox.Show (v.Name & " has an id
attribute")
End If
Next
End If
End If
Next
End If
End While
v.Close()
End Sub
Private Sub VEH(ByVal sender As Object, ByVal e As
System.Xml.Sche ma.ValidationEv entArgs)
Debug.WriteLine (e.Message)
End Sub
"JMonnin" wrote:
I'm using an XmlValidatingRe ader to read an XML document and parse it against
my schema. While I'm reading each node, I need to determine if the schema
allows an ID attribute for the node. The ID is optional so it may not exist
in the XML document. Is there a way to determine if the attribute is allowed
or not? I can't seem to find any information on this anywhere.