Hi:
The problem I am having is when I validate an xml file to a schema, it is
erroring out every element. I think this has something to do with me
defining/referencing the namespaces. I have searched on the net for a
while, but am still confused. Thanks in advance for help. Below is the
code I am working with. What am I not referencing/referencing incorrectly?
===================================
Output when trying to validate:
Message: The element 'urn:PeopleQuery:query' has invalid child element
'urn:PeopleQuery:match'. Expected 'match'. An error occurred at
file:///c:/inetpub/wwwroot/PeopleSearch/query.xml, (3, 3).
Message: The 'urn:PeopleQuery:match' element is not declared. An error
occurred at file:///c:/inetpub/wwwroot/PeopleSearch/query.xml, (3, 3).
Message: Could not find schema information for the attribute 'field'. An
error occurred at file:///c:/inetpub/wwwroot/PeopleSearch/query.xml, (3, 9).
Message: Could not find schema information for the attribute 'comparison'.
An error occurred at file:///c:/inetpub/wwwroot/PeopleSearch/query.xml, (3,
26).
Message: Could not find schema information for the attribute 'value'. An
error occurred at file:///c:/inetpub/wwwroot/PeopleSearch/query.xml, (3,
46).
====================================
My query.xml
<?xml version="1.0" encoding="utf-8" ?>
<query xmlns="urn:PeopleQuery">
<match field="lastname" comparison="equals" value="smith" />
</query>
=====================================
My peoplequery.xsd
<?xml version="1.0" ?>
<xs:schema targetNamespace="urn:PeopleQuery"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:PeopleQuery" >
<xs:element name="query">
<xs:complexType>
<xs:sequence>
<xs:element name="match">
<xs:complexType>
<xs:attribute name="field" type="xs:string" use="required" />
<xs:attribute name="comparison" use="required">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="equals|contains|starts with|ends with" />
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="value" type="xs:string" use="required" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
=======================================
VB .NET code that compares them and puts the output
Private Function validatexml()
Dim oTR As System.Xml.XmlTextReader
Dim oVR As System.Xml.XmlValidatingReader
oTR = New System.Xml.XmlTextReader(Server.MapPath("query.xml "))
oVR = New System.Xml.XmlValidatingReader(oTR)
oVR.Schemas.Add("urn:PeopleQuery",
Server.MapPath("PeopleQuery.xsd"))
oVR.ValidationType = Xml.ValidationType.Schema
AddHandler oVR.ValidationEventHandler, AddressOf ValidationHandler
While oVR.Read()
End While
End Function
Private Sub ValidationHandler(ByVal sender As Object, ByVal args As
System.Xml.Schema.ValidationEventArgs)
Response.Write("Message: " & args.Message & "<br>")
End Sub
=========================================