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

XmlSchema.Read -> nothing happens

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
4 7094
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AlexS | last post by:
Hello, I have error when reading schema using XmlSchema. Read and then .Compile: System.Xml.Schema.XmlSchemaException: May not be nominated as the {substitution group affiliation} of any...
0
by: Sinic101 | last post by:
I'm using the following code to create an XmlSchema from an XSD file. The Read() method doesn't throw any errors and after I write the schema to a file, it looks as expected However, after the...
2
by: Alex Shirshov | last post by:
Hello, All! It seems the bug (http://groups.google.com/groups?hl=ru&lr=&ie=UTF-8&threadm=a53b01c28a00%242 08bc860%2439ef2ecf%40TKMSFTNGXA08&rnum=8&prev=/groups%3Fq%3DschemaLocation%2...
1
by: SideByEach | last post by:
If I wanted to find the type referenced in this XML's root node, what object would I use in the SOM? <xs:schema xmlns="http://www.w3.org/1999/XSL/Transform"elementFormDefault="qualified" ...
0
by: sudha | last post by:
I need to read an xml file which has xmlschema in it to create a csv file. I need to generate column names from xmlschema. How should I read xmlschema inside the xml file to generate columnnames?...
1
by: Steve | last post by:
For some reason, the schema seems to be empty every time it's loaded. Does anyone have any ideas?? Thanks! Here's the code: Dim xsd As System.Xml.Schema.XmlSchema Dim io As New...
2
by: MyndPhlyp | last post by:
I am attempting to write a DLL to maintain an XML file. It creates its own XSD as an XmlSchema (or even a compiled member of an XmlSchemaSet, if necessary). I don't want to write an XSD to disk....
1
by: hemendravyas | last post by:
Please help out in following code snippet: For the first time it gives prompt while XmlSchema.Read(). Second time schema_collection_object is not null and so does not enter into this block of...
1
by: Ryan | last post by:
Hello Xml Gurus, I'm trying to build an XML schema in memory using the System.Xml.XmlSchema namespace objects, validate it, and then write it to a file. The problem I'm facing is that...
0
by: =?Utf-8?B?TGFzdGJ1aWxkZXJz?= | last post by:
Hi all, I have a weird problem which has been causing me a headache for the last two days. I have to dynamicly generate a schema in memory and load it into a dataset in memory to be returned...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.