473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with Schema validation erroring out every single element

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

=========================================


Nov 12 '05 #1
2 5067
"Tarren" <noemailplease@thankyou> wrote in message news:uy*************@tk2msftngp13.phx.gbl...
erroring out every element. I think this has something to do with me
defining/referencing the namespaces. : : Output when trying to validate:
Message: The element 'urn:PeopleQuery:query' has invalid child element
'urn:PeopleQuery:match'. Expected 'match'. : : <xs:schema targetNamespace="urn:PeopleQuery"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:PeopleQuery" >


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
Nov 12 '05 #2
Thanks, Derek. That was it exactly - thanks for the explanation as well.
Very helpful! :)
"Derek Harmon" <lo*******@msn.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
"Tarren" <noemailplease@thankyou> wrote in message
news:uy*************@tk2msftngp13.phx.gbl...
erroring out every element. I think this has something to do with me
defining/referencing the namespaces.

: :
Output when trying to validate:
Message: The element 'urn:PeopleQuery:query' has invalid child element
'urn:PeopleQuery:match'. Expected 'match'.

: :
<xs:schema targetNamespace="urn:PeopleQuery"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="urn:PeopleQuery" >


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

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Val Melamed | last post by:
Hi all, These days I'm playing with schemas and SOM from MSXML. To learn it I used the excellent tutorial from Mr.Costello: http://www.xfront.com/xml-schema.html. while working through the...
9
by: brandon | last post by:
I want to speed up the validation of some of my fairly large and detailed XML files. In particular there is a set of child elements and attributes that does not to be validated after it has...
0
by: Rajesh Jain | last post by:
I Have 2 separate schemas. --------------Schema 1 is defined as below----------- <xs:schema targetNamespace="http://Schemas/1" xmlns="http://Schemas/1" xmlns:xs="http://www.w3.org/2001/XMLSchema"...
4
by: Iain A. Mcleod | last post by:
Hi I'm stuck with the following schema validation problem in VS.NET 2003: I have two types of xml document and related schema: project and projectCollection. A projectcollection is just a set...
1
by: Dan Bass | last post by:
There's an XML message I have, that has no namespace information. Then there is a XSD schema that is must validate against, but this has a targetNamespace and xmlns of...
0
by: Mark Parter | last post by:
I'm trying convert an XML Schema (http://www.elframework.org/projects/xcri/efc_r1.0.xsd/view) to a VB.Net class using the XSD tool provided with the .NET 2 SDK. However, it's failing to generate...
2
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
9
by: mstilli | last post by:
Hi, I am trying to use schema for server side validation using xerces to catch the validation errors. validating this XML: <Content4> <textarea13></textarea13>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.