By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,263 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

XmlSchema.Read -> nothing happens

P: n/a
Hi,

I'm trying to load a schema into an XmlSchema object with the Read and
Compile methods. I use Read with a ValidationEventHandler. No errors
occurs but when I look at the XmlSchema properties it contains
NOTHING. The schema file is correct because I can use it to validate
xmldocuments with the XMLValidatingReader. What am I doing wrong here?

Code:

Dim xs As New Xml.Schema.XmlSchema()
Dim fs = New IO.FileStream("test.xsd", IO.FileMode.Open)

xs.Read(fs, New Xml.Schema.ValidationEventHandler(AddressOf
ValidationCallback))
xs.Compile(AddressOf ValidationCallback)
Thanks in advance,

Stefan
Nov 12 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
The only problem that I see is that Read is a static function. Following
code works for me:

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Module Module1
Dim s = "<xs:schema targetNamespace='uri_tns'
xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='foo'
type='xs:string' /><xs:attribute name='bar' type='xs:int' /></xs:schema>"
Sub Main()
Dim schema As XmlSchema
schema = XmlSchema.Read(New StringReader(s), AddressOf
ValidationCallbackOne)
schema.Compile(AddressOf ValidationCallbackOne)
schema.Write(Console.Out)
End Sub
Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As
ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub 'ValidationCallbackOne
End Module
"Stefan Rotter" <st****@vemendo.se> wrote in message
news:bf**************************@posting.google.c om...
Hi,

I'm trying to load a schema into an XmlSchema object with the Read and
Compile methods. I use Read with a ValidationEventHandler. No errors
occurs but when I look at the XmlSchema properties it contains
NOTHING. The schema file is correct because I can use it to validate
xmldocuments with the XMLValidatingReader. What am I doing wrong here?

Code:

Dim xs As New Xml.Schema.XmlSchema()
Dim fs = New IO.FileStream("test.xsd", IO.FileMode.Open)

xs.Read(fs, New Xml.Schema.ValidationEventHandler(AddressOf
ValidationCallback))
xs.Compile(AddressOf ValidationCallback)
Thanks in advance,

Stefan

Nov 12 '05 #2

P: n/a
The only problem that I see is that Read is a static function. Following
code works for me:

Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Schema
Module Module1
Dim s = "<xs:schema targetNamespace='uri_tns'
xmlns:xs='http://www.w3.org/2001/XMLSchema'><xs:element name='foo'
type='xs:string' /><xs:attribute name='bar' type='xs:int' /></xs:schema>"
Sub Main()
Dim schema As XmlSchema
schema = XmlSchema.Read(New StringReader(s), AddressOf
ValidationCallbackOne)
schema.Compile(AddressOf ValidationCallbackOne)
schema.Write(Console.Out)
End Sub
Sub ValidationCallbackOne(ByVal sender As Object, ByVal args As
ValidationEventArgs)
Console.WriteLine(args.Message)
End Sub 'ValidationCallbackOne
End Module
"Stefan Rotter" <st****@vemendo.se> wrote in message
news:bf**************************@posting.google.c om...
Hi,

I'm trying to load a schema into an XmlSchema object with the Read and
Compile methods. I use Read with a ValidationEventHandler. No errors
occurs but when I look at the XmlSchema properties it contains
NOTHING. The schema file is correct because I can use it to validate
xmldocuments with the XMLValidatingReader. What am I doing wrong here?

Code:

Dim xs As New Xml.Schema.XmlSchema()
Dim fs = New IO.FileStream("test.xsd", IO.FileMode.Open)

xs.Read(fs, New Xml.Schema.ValidationEventHandler(AddressOf
ValidationCallback))
xs.Compile(AddressOf ValidationCallback)
Thanks in advance,

Stefan

Nov 12 '05 #3

P: n/a
Read is a static method on XmlSchema class. It will create a new XmlSchema
object and return that.
Hence if you call it on a schema object that you already created, that does
not reflect the parsed schema returned by the Read method.

Code sample in c#:
FileStream fs = new FileStream("test.xsd", FileMode.Open);
XmlSchema schema = XmlSchema.Read( fs, new
ValidationEventHandler(ValidationCallback));
schema.Compile();

Thanks,
Priya

"Stefan Rotter" <st****@vemendo.se> wrote in message
news:bf**************************@posting.google.c om...
Hi,

I'm trying to load a schema into an XmlSchema object with the Read and
Compile methods. I use Read with a ValidationEventHandler. No errors
occurs but when I look at the XmlSchema properties it contains
NOTHING. The schema file is correct because I can use it to validate
xmldocuments with the XMLValidatingReader. What am I doing wrong here?

Code:

Dim xs As New Xml.Schema.XmlSchema()
Dim fs = New IO.FileStream("test.xsd", IO.FileMode.Open)

xs.Read(fs, New Xml.Schema.ValidationEventHandler(AddressOf
ValidationCallback))
xs.Compile(AddressOf ValidationCallback)
Thanks in advance,

Stefan

Nov 12 '05 #4

P: n/a
Read is a static method on XmlSchema class. It will create a new XmlSchema
object and return that.
Hence if you call it on a schema object that you already created, that does
not reflect the parsed schema returned by the Read method.

Code sample in c#:
FileStream fs = new FileStream("test.xsd", FileMode.Open);
XmlSchema schema = XmlSchema.Read( fs, new
ValidationEventHandler(ValidationCallback));
schema.Compile();

Thanks,
Priya

"Stefan Rotter" <st****@vemendo.se> wrote in message
news:bf**************************@posting.google.c om...
Hi,

I'm trying to load a schema into an XmlSchema object with the Read and
Compile methods. I use Read with a ValidationEventHandler. No errors
occurs but when I look at the XmlSchema properties it contains
NOTHING. The schema file is correct because I can use it to validate
xmldocuments with the XMLValidatingReader. What am I doing wrong here?

Code:

Dim xs As New Xml.Schema.XmlSchema()
Dim fs = New IO.FileStream("test.xsd", IO.FileMode.Open)

xs.Read(fs, New Xml.Schema.ValidationEventHandler(AddressOf
ValidationCallback))
xs.Compile(AddressOf ValidationCallback)
Thanks in advance,

Stefan

Nov 12 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.