473,671 Members | 2,214 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLValidatingRe ader desperate...

Hi all,

I'm quite desperate after so much time of frustration trying to
validate an xml doc with a schema using XmlValidatingRe ader. I know I
miss something but I cannot solve this for the life of me:

My xsd is:

<xs:schema targetNamespace ="http://myUrl.com"
elementFormDefa ult="qualified"
attributeFormDe fault="qualifie d" xmlns:a="http://myUrl.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
....
....
<xs:element name="mainNode" >...

The xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<mainNode xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://myUrl.com">
.....
other elements here...
</mainNode>

This is my code using XmlValidatingRe ader:

Dim _reader As New XmlValidatingRe ader(xmlFragmen t,
XmlNodeType.Ele ment, Nothing)
Dim _xsc As New XmlSchemaCollec tion

__isValid = True

_xsc.Add("http://myUrl.com", New XmlTextReader(s chema))

' I have tried this as well:
'_xsc.Add(Nothi ng, New XmlTextReader(s chema))

_reader.Schemas .Add(_xsc)
_reader.Validat ionType = ValidationType. Schema

AddHandler _reader.Validat ionEventHandler , AddressOf
ValidationCallB ack

While _reader.Read()
End While
....

And the ValidationCallB ack sub just changes the value of __isValid to
false.

Anytime I call the validation routine it returns false and the message
error is:
The 'mainNode' element is not declared. An error at , (..)

If I changed the elementFormDefa ul and attributeFormDe fault to
"unqualifie d" everything is fine.

I would prefer buying you beer rather than banging my head against the
walls.

Paul

Nov 12 '05 #1
1 1110
You don't declare default namespace in your xml document, so the validator
doesn't find the mainNode element in your schema. Change your xml file to
read:

<mainNode xmlns="http://myUrl.com">
...
</mainNode>

It doesn't look like you were using the other two namespaces, so I removed
them. If you need them, feel free to put them back. Also, you haven't
defined the default namespace in your schema, which might cause some
problems. Since you haven't posted the entire schema, I can't tell. And
finally, you might want to change the attributeFormDe fault to "unqualifie d".

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.

<so*****@hotmai l.com> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Hi all,

I'm quite desperate after so much time of frustration trying to
validate an xml doc with a schema using XmlValidatingRe ader. I know I
miss something but I cannot solve this for the life of me:

My xsd is:

<xs:schema targetNamespace ="http://myUrl.com"
elementFormDefa ult="qualified"
attributeFormDe fault="qualifie d" xmlns:a="http://myUrl.com"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
...
...
<xs:element name="mainNode" >...

The xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<mainNode xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"
xmlns:a="http://myUrl.com">
....
other elements here...
</mainNode>

This is my code using XmlValidatingRe ader:

Dim _reader As New XmlValidatingRe ader(xmlFragmen t,
XmlNodeType.Ele ment, Nothing)
Dim _xsc As New XmlSchemaCollec tion

__isValid = True

_xsc.Add("http://myUrl.com", New XmlTextReader(s chema))

' I have tried this as well:
'_xsc.Add(Nothi ng, New XmlTextReader(s chema))

_reader.Schemas .Add(_xsc)
_reader.Validat ionType = ValidationType. Schema

AddHandler _reader.Validat ionEventHandler , AddressOf
ValidationCallB ack

While _reader.Read()
End While
...

And the ValidationCallB ack sub just changes the value of __isValid to
false.

Anytime I call the validation routine it returns false and the message
error is:
The 'mainNode' element is not declared. An error at , (..)

If I changed the elementFormDefa ul and attributeFormDe fault to
"unqualifie d" everything is fine.

I would prefer buying you beer rather than banging my head against the
walls.

Paul

Nov 12 '05 #2

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

Similar topics

9
1934
by: jason | last post by:
how do you use the XmlValidatingReader to validate an XML document that is passed into the XmlValidatingReader constructor? it looks like the normal process is to use an underlying reader, as follows (C#): XmlValidatingReader oMyVReader = new XmlValidatingReader(oMyReader); oMyVReader.Schemas.Add(oMySchemaCollection); oMyVReader.ValidationType = ValidationType.Schema;
5
1409
by: Geoff | last post by:
I am using an XMLValidatingReader to validate an XML file received via a web service. I want to verify that the incoming file matches the XML schema. When testing the validation routine, the XMLValidatingReader correctly flags mis-matched tags such as <abc>some content</xyz> but does not catch other errors. For example, it doesn't catch tags that are not part of the schema, doesn't catch missing tags where the schema has minoccurs="1", and...
1
1840
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST> xml file 2
12
8555
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
0
8392
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8912
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8669
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4403
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.