help with Schema validation erroring out every single element |
P: n/a
|
Tarren
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
========================================= | |
Share this Question
|
P: n/a
|
Derek Harmon
"Tarren" <noemailplease@thankyou> wrote in message news:uyS0aV$mEHA.648@tk2msftngp13.phx.gbl...[color=blue]
> erroring out every element. I think this has something to do with me
> defining/referencing the namespaces.[/color]
: :[color=blue]
> Output when trying to validate:
> Message: The element 'urn:PeopleQuery:query' has invalid child element
> 'urn:PeopleQuery:match'. Expected 'match'.[/color]
: :[color=blue]
> <xs:schema targetNamespace="urn:PeopleQuery"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="urn:PeopleQuery" >[/color]
What you need is an elementFormDefault attribute on the
<xs:schema> element. Try using the following <xs:schema>
instead:
<xs:schema
targetNamespace="urn:PeopleQuery"
elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:PeopleQuery" >
The dead giveaway was that the XmlValidatingReader _did_
expect to find an element named "match," but that element
was not qualified by your target namespace URI.
Note that instead of changing the default element qualification
for the entire schema, it's also possible to change the element
qualification on individual <xs:element>s like this,
<xs:element name="match" form="qualified" >
The default value for elementFormDefault was 'unqualified'.
In this case, only the document element is qualified by the
targetNamespace specified on the <xs:schema>. When
your XML Schema targets a namespace, the global element
(in this case, "query") must at least be namespace qualified.
However, other whether other elements are qualified by a
namespace URI is an open question that the XML Schema
designer must answer by applying elementFormDefault
and/or form attributes in the appropriate places.
HTH,
Derek Harmon | | |
P: n/a
|
Tarren
Thanks, Derek. That was it exactly - thanks for the explanation as well.
Very helpful! :)
"Derek Harmon" <loresayer@msn.com> wrote in message
news:%23K20wlGnEHA.3992@TK2MSFTNGP15.phx.gbl...[color=blue]
> "Tarren" <noemailplease@thankyou> wrote in message
> news:uyS0aV$mEHA.648@tk2msftngp13.phx.gbl...[color=green]
>> erroring out every element. I think this has something to do with me
>> defining/referencing the namespaces.[/color]
> : :[color=green]
>> Output when trying to validate:
>> Message: The element 'urn:PeopleQuery:query' has invalid child element
>> 'urn:PeopleQuery:match'. Expected 'match'.[/color]
> : :[color=green]
>> <xs:schema targetNamespace="urn:PeopleQuery"
>> xmlns:xs="http://www.w3.org/2001/XMLSchema"
>> xmlns="urn:PeopleQuery" >[/color]
>
> What you need is an elementFormDefault attribute on the
> <xs:schema> element. Try using the following <xs:schema>
> instead:
>
> <xs:schema
> targetNamespace="urn:PeopleQuery"
> elementFormDefault="qualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns="urn:PeopleQuery" >
>
> The dead giveaway was that the XmlValidatingReader _did_
> expect to find an element named "match," but that element
> was not qualified by your target namespace URI.
>
> Note that instead of changing the default element qualification
> for the entire schema, it's also possible to change the element
> qualification on individual <xs:element>s like this,
>
> <xs:element name="match" form="qualified" >
>
> The default value for elementFormDefault was 'unqualified'.
> In this case, only the document element is qualified by the
> targetNamespace specified on the <xs:schema>. When
> your XML Schema targets a namespace, the global element
> (in this case, "query") must at least be namespace qualified.
>
> However, other whether other elements are qualified by a
> namespace URI is an open question that the XML Schema
> designer must answer by applying elementFormDefault
> and/or form attributes in the appropriate places.
>
>
> HTH,
>
> Derek Harmon
>
>[/color] | | Post your reply Help answer this question
Didn't find the answer to your .NET Framework question?
| | Question stats - viewed: 3285
- replies: 2
- date asked: Nov 12 '05
| |