473,397 Members | 2,099 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,397 software developers and data experts.

Validation of XML with XmlValidatingReader

JB
Having problems with this:

schema is:

<xs:schema xmlns="xsdPayment" targetNamespace="xsdPayment"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Payment" type="PAYMENT" />
<xs:complexType name="PAYMENT">
<xs:sequence>
<xs:element name="Receipt_Nbr" type="xs:string"
maxOccurs="unbounded" />
<xs:element name="Amount" type="xs:decimal" />
<xs:element name="LastName" type="xs:string" />
<xs:element name="FirstName" type="xs:string" />
<xs:element name="DOB" type="xs:date" />
<xs:element name="DatePaid" type="xs:date" />
<xs:element name="Case_ID" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

sample data xml:
<pay:Payments xmlns:pay='xsdPayments' xsi:schemaLocation='xsdPayments
Payments.xsd' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<PAYMENT>
<CASE_ID>RE/2004-123456</CASE_ID>
<RECEIPT_NO>123ABC</RECEIPT_NO>
<DATE>2000-05-01</DATE>
<AMOUNT>51.55</AMOUNT>
<GIVEN_NAMES>GEORGE FRED</GIVEN_NAMES>
<LAST_NAME>SMITH</LAST_NAME>
<DOB>1975-12-30</DOB>
</PAYMENT>
<PAYMENT>
<CASE_ID>RE/2004-123457</CASE_ID>
<RECEIPT_NO>124ABC</RECEIPT_NO>
<DATE>2000-05-01</DATE>
<AMOUNT>77.22</AMOUNT>
<GIVEN_NAMES>GEORGE FRED</GIVEN_NAMES>
<LAST_NAME>SMITH</LAST_NAME>
<DOB>1954-02-03</DOB>
</PAYMENT>
<PAYMENT>
<CASE_ID>RE/2004-123458</CASE_ID>
<RECEIPT_NO>125ABC</RECEIPT_NO>
<DATE>2000-05-01</DATE>
<AMOUNT>88.88</AMOUNT>
<GIVEN_NAMES>GEORGE FRED</GIVEN_NAMES>
<LAST_NAME>SMITH</LAST_NAME>
<DOB>1969-11-13</DOB>
</PAYMENT>
</hc:Payments>

VB.NET Calling code is:
Try

Dim tr As New XmlTextReader(_path)
Dim vr As New XmlValidatingReader(tr)

vr.ValidationType = ValidationType.Schema
AddHandler vr.ValidationEventHandler, AddressOf
ValidationHandler

While vr.Read
End While
Catch ex1 As Exception
MessageBox.Show(ex1.ToString)
Finally
'Stream.Close()
'vReader.Close()
'End
End Try

Public Shared Sub ValidationHandler(ByVal sender As Object, ByVal
args As ValidationEventArgs)
MessageBox.Show(args.Message)
End Sub

args.Message =
"The attribute targetNamespace does not match the designated namespace
URI. An error occurred at file: ...blah
blah.../WindowsApplication1/Payments.xsd, (1, 2).

Anybody spot the mistake? I'm stumped.

TIA

JB
Nov 12 '05 #1
1 1207
JB wrote:

<xs:schema xmlns="xsdPayment" targetNamespace="xsdPayment" <pay:Payments xmlns:pay='xsdPayments' xsi:schemaLocation='xsdPayments


You've got a typo here:
"xsdPayment" != "xsdPayments"

--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Nov 12 '05 #2

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

Similar topics

2
by: Sudip Chakraborty | last post by:
Is there a way to see constraint validation errors while loading xml into a DataSet ? I'm interested in the line number in the xml file which is causing the error. I've enclosed the relevant stack...
1
by: eXavier | last post by:
Hi, I need to validate XML fragment against XSD schema. The main issue is that xml fragment does not contain refrence to schema, but I want to force the validation against the schema I have in...
18
by: Vlad | last post by:
I have the following code: I have a local copy of the DTD that I need to validate incoming XML documents against. The XML document has the <!DOCTYPE myname SYSTEM "myfile.dtd"> define. When the...
2
by: Matthew | last post by:
I have implemented the xmlSchemaCollection object to cache commonly used schemas, as follows: =============================================================================== public void...
3
by: Dave | last post by:
Hi, I'm really confused as to how to validate XML fragments against a schema in C#. I am creating XML through an automated process and have an .xsd which was given to me to validate against....
0
by: Matt | last post by:
I have a problem when I select node elements from an xml file and validata each node againts the schema. I use XmlValidatingReader and it complains about elements not being declared. I have...
1
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException :...
1
by: BillAtWork | last post by:
Hi, I'm trying to validate an XML document against an XSD schema and I receive the following error: ---------- MyCode.CreateValidRequest : System.Web.Services.Protocols.SoapException :...
5
by: paul_zaoldyeck | last post by:
does anyone know how to validate an xml file against multiple defined schema? can you show me some examples? i'm making here an xml reader.. thank you
0
by: Nadeeka | last post by:
Hi, I wrote a Schema Validator in C#.NET. XmlTextReader R = new XmlTextReader(FileToParse); XmlValidatingReader V = new XmlValidatingReader(R); try ...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.