XML Brain Death Has Occured at 18:19 PM GMT

  • Thread starter One Handed Man \( OHM - Terry Burns \)
  • Start date
O

One Handed Man \( OHM - Terry Burns \)

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
 
H

Hexathioorthooxalate

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
 
O

One Handed Man \( OHM - Terry Burns \)

Ahhh!, ok I'l report back !

Ta!

--

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

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

One Handed Man \( OHM - Terry Burns \)

Top Geezer

Thats it mate ! - Cheers

--

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top