473,382 Members | 1,420 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,382 software developers and data experts.

XML Brain Death Has Occured at 18:19 PM GMT

Yes, my brain is once again dead ( this is my mind writing using a
supernatural force ).

I'm trying to validate an xml file against its schema, I have a very simple
example where price is a float, and I put a text value in its place to test
validation. "Nothing Is Reported", however, when I use the IDE to validate
it, it complains as expected. Where have I gone wrong ?

'// THIS IS MY PUNY LITTLE XML FILE '//
<?xml version="1.0" encoding="utf-8"?>
<STORE xmlns="http://tempuri.org/DATA.xsd">
<PRODUCT genre="general">
<PRICE>THIS SHOULD BE A FLOAT</PRICE>
</PRODUCT>
</STORE>
'// THIS IS MY XSD SCHEMA FILE
<?xml version="1.0" ?>
<xs:schema id="STORE" targetNamespace="http://tempuri.org/DATA.xsd"
xmlns:mstns="http://tempuri.org/DATA.xsd"
xmlns="http://tempuri.org/DATA.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="STORE" msdata:IsDataSet="true" msdata:Locale="en-GB"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="PRODUCT">
<xs:complexType>
<xs:sequence>
<xs:element name="PRICE" type="xs:float" minOccurs="0"
msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="genre" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

'// Code - Validator declared at class level
Private WithEvents validatingReader As XmlValidatingReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim reader As XmlTextReader

Try
reader = New XmlTextReader("..\DATA.xml")
validatingReader = New XmlValidatingReader(reader)
validatingReader.ValidationType = ValidationType.Schema

While validatingReader.Read()
'nothing
End While

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
reader.Close()
End Try
End Sub
Private Sub validatingReader_ValidationEventHandler(ByVal sender As
Object, ByVal e As System.Xml.Schema.ValidationEventArgs) Handles
validatingReader.ValidationEventHandler
Debug.WriteLine(e.Exception.Message)
End Sub

--

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing
Nov 20 '05 #1
3 1088
Hey Terry, your XML application is both well formed and valid.

Although I haven't tested it, your problem is most certainly because you
haven't told your XML where to find the schema for validation.

Add something like

validatingReader.schemas.add("http://tempuri.org/DATA.xsd", "..\DATA.xsd")
//or whatever schema filename is

to your VB.Net code and you should be away laughing.

Regards
Hex



"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
Yes, my brain is once again dead ( this is my mind writing using a
supernatural force ).

I'm trying to validate an xml file against its schema, I have a very simple example where price is a float, and I put a text value in its place to test validation. "Nothing Is Reported", however, when I use the IDE to validate
it, it complains as expected. Where have I gone wrong ?

'// THIS IS MY PUNY LITTLE XML FILE '//
<?xml version="1.0" encoding="utf-8"?>
<STORE xmlns="http://tempuri.org/DATA.xsd">
<PRODUCT genre="general">
<PRICE>THIS SHOULD BE A FLOAT</PRICE>
</PRODUCT>
</STORE>
'// THIS IS MY XSD SCHEMA FILE
<?xml version="1.0" ?>
<xs:schema id="STORE" targetNamespace="http://tempuri.org/DATA.xsd"
xmlns:mstns="http://tempuri.org/DATA.xsd"
xmlns="http://tempuri.org/DATA.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="STORE" msdata:IsDataSet="true" msdata:Locale="en-GB"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="PRODUCT">
<xs:complexType>
<xs:sequence>
<xs:element name="PRICE" type="xs:float" minOccurs="0"
msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="genre" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

'// Code - Validator declared at class level
Private WithEvents validatingReader As XmlValidatingReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim reader As XmlTextReader

Try
reader = New XmlTextReader("..\DATA.xml")
validatingReader = New XmlValidatingReader(reader)
validatingReader.ValidationType = ValidationType.Schema

While validatingReader.Read()
'nothing
End While

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
reader.Close()
End Try
End Sub
Private Sub validatingReader_ValidationEventHandler(ByVal sender As
Object, ByVal e As System.Xml.Schema.ValidationEventArgs) Handles
validatingReader.ValidationEventHandler
Debug.WriteLine(e.Exception.Message)
End Sub

--

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

Nov 20 '05 #2
Ahhh!, ok I'l report back !

Ta!

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in message
news:10***************@ersa.uk.clara.net...
Hey Terry, your XML application is both well formed and valid.

Although I haven't tested it, your problem is most certainly because you
haven't told your XML where to find the schema for validation.

Add something like

validatingReader.schemas.add("http://tempuri.org/DATA.xsd", "..\DATA.xsd") //or whatever schema filename is

to your VB.Net code and you should be away laughing.

Regards
Hex



"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ui**************@tk2msftngp13.phx.gbl...
Yes, my brain is once again dead ( this is my mind writing using a
supernatural force ).

I'm trying to validate an xml file against its schema, I have a very

simple
example where price is a float, and I put a text value in its place to

test
validation. "Nothing Is Reported", however, when I use the IDE to validate it, it complains as expected. Where have I gone wrong ?

'// THIS IS MY PUNY LITTLE XML FILE '//
<?xml version="1.0" encoding="utf-8"?>
<STORE xmlns="http://tempuri.org/DATA.xsd">
<PRODUCT genre="general">
<PRICE>THIS SHOULD BE A FLOAT</PRICE>
</PRODUCT>
</STORE>
'// THIS IS MY XSD SCHEMA FILE
<?xml version="1.0" ?>
<xs:schema id="STORE" targetNamespace="http://tempuri.org/DATA.xsd"
xmlns:mstns="http://tempuri.org/DATA.xsd"
xmlns="http://tempuri.org/DATA.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="STORE" msdata:IsDataSet="true" msdata:Locale="en-GB"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="PRODUCT">
<xs:complexType>
<xs:sequence>
<xs:element name="PRICE" type="xs:float" minOccurs="0"
msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="genre" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

'// Code - Validator declared at class level
Private WithEvents validatingReader As XmlValidatingReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim reader As XmlTextReader

Try
reader = New XmlTextReader("..\DATA.xml")
validatingReader = New XmlValidatingReader(reader)
validatingReader.ValidationType = ValidationType.Schema

While validatingReader.Read()
'nothing
End While

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
reader.Close()
End Try
End Sub
Private Sub validatingReader_ValidationEventHandler(ByVal sender As
Object, ByVal e As System.Xml.Schema.ValidationEventArgs) Handles
validatingReader.ValidationEventHandler
Debug.WriteLine(e.Exception.Message)
End Sub

--

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing


Nov 20 '05 #3
Top Geezer

Thats it mate ! - Cheers

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Hexathioorthooxalate" <ru***@spameremove.clara.co.uk> wrote in message
news:10***************@ersa.uk.clara.net...
Hey Terry, your XML application is both well formed and valid.

Although I haven't tested it, your problem is most certainly because you
haven't told your XML where to find the schema for validation.

Add something like

validatingReader.schemas.add("http://tempuri.org/DATA.xsd", "..\DATA.xsd") //or whatever schema filename is

to your VB.Net code and you should be away laughing.

Regards
Hex



"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:ui**************@tk2msftngp13.phx.gbl...
Yes, my brain is once again dead ( this is my mind writing using a
supernatural force ).

I'm trying to validate an xml file against its schema, I have a very

simple
example where price is a float, and I put a text value in its place to

test
validation. "Nothing Is Reported", however, when I use the IDE to validate it, it complains as expected. Where have I gone wrong ?

'// THIS IS MY PUNY LITTLE XML FILE '//
<?xml version="1.0" encoding="utf-8"?>
<STORE xmlns="http://tempuri.org/DATA.xsd">
<PRODUCT genre="general">
<PRICE>THIS SHOULD BE A FLOAT</PRICE>
</PRODUCT>
</STORE>
'// THIS IS MY XSD SCHEMA FILE
<?xml version="1.0" ?>
<xs:schema id="STORE" targetNamespace="http://tempuri.org/DATA.xsd"
xmlns:mstns="http://tempuri.org/DATA.xsd"
xmlns="http://tempuri.org/DATA.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
attributeFormDefault="qualified" elementFormDefault="qualified">
<xs:element name="STORE" msdata:IsDataSet="true" msdata:Locale="en-GB"
msdata:EnforceConstraints="False">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="PRODUCT">
<xs:complexType>
<xs:sequence>
<xs:element name="PRICE" type="xs:float" minOccurs="0"
msdata:Ordinal="0" />
</xs:sequence>
<xs:attribute name="genre" form="unqualified" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>

'// Code - Validator declared at class level
Private WithEvents validatingReader As XmlValidatingReader

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim reader As XmlTextReader

Try
reader = New XmlTextReader("..\DATA.xml")
validatingReader = New XmlValidatingReader(reader)
validatingReader.ValidationType = ValidationType.Schema

While validatingReader.Read()
'nothing
End While

Catch ex As Exception
Debug.WriteLine(ex.ToString)
Finally
reader.Close()
End Try
End Sub
Private Sub validatingReader_ValidationEventHandler(ByVal sender As
Object, ByVal e As System.Xml.Schema.ValidationEventArgs) Handles
validatingReader.ValidationEventHandler
Debug.WriteLine(e.Exception.Message)
End Sub

--

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing


Nov 20 '05 #4

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

Similar topics

0
by: Aahz | last post by:
Pre-announcement: Our May meeting will be the *THIRD* Thursday, May 19. We will *NOT* be meeting the *SECOND* Thursday. This will be our first meeting at Google, with Alex Martelli's...
7
by: robert | last post by:
running 8.1.7 server, 8.1.6 client. i *thought* inner join should not return nulls, but not only that, but i get way more rows than i'm expecting. assume: order table: order_number
2
by: mjweiner | last post by:
This one has been stumping me for several days. I can run a query that returns several different items from several different manufacturers, each with a ranking score. Each manufacturer can have...
28
by: Siv | last post by:
Hi, If I run the following: strSQL = "Select * FROM Clients;" da = New OleDb.OleDbDataAdapter(strSQL, Conn) 'Create data adapter cb = New OleDb.OleDbCommandBuilder(da) ...
15
by: Chung Leong | last post by:
Here's a little brain teaser distilled from a bug that took me a rather long time to figure out. The two functions in the example below behave differently. The difference is easy to spot, of...
7
by: 511475 | last post by:
What is the best checker to use to find these probles with, besides an experienced set of eyes? This probram is to grade the response to input by user. Grades his marks. Thanks <?xml...
95
by: viv342 | last post by:
how can two variables be swapped without using a third variable?
11
by: arnuld | last post by:
STATEMENT: Write a program that prompts the user for two numbers and writes each number in the range specified by the two numbers to the standard output. Revise the program so that it never...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.