473,659 Members | 2,645 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

namespace problem during validation

Hi !

I have problem with validating of the document with multiple
namespaces. The odd thing is, that my data work O'K when I test it
under XMLSpy but it doesn't work with my C# code.

My first 'main' schema is as follows:
incr2.xsd
----------
<xs:schema targetNamespace ="http://vit.volvo.com/dept9272/2004/ESB"
xmlns:p="tnsper son" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:import namespace="tnsp erson" schemaLocation= "incr11.xsd "/>
<xs:element name="record">
<xs:complexTy pe >
<xs:sequence>
<xs:element ref="p:person"/>
<xs:element name="info" type="xs:string "/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

As you can see, it imports another schema,
incr11.xsd
----------
<xs:schema targetNamespace ="tnsperson" xmlns:t = "tnsperson"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexTy pe name="persontyp e">
<xs:sequence>
<xs:element name="firstname " type="xs:string "/>
<xs:element name="lastname" type="xs:string "/>
<xs:element name="age" type="xs:string "/>
</xs:sequence>
</xs:complexType>
<xs:element name="person" type="t:persont ype">
</xs:element>
</xs:schema>

The sample document is here:
sample.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns="http://vit.volvo.com/dept9272/2004/ESB"
xmlns:p="tnsper son" >
<person xmlns="tnsperso n">
<firstname>To m</firstname>
<lastname>Rom </lastname>
<age>22</age>
</person>
<info>x_info</info>
</record>

The error message is as follows:
*************** **
The element 'tnsperson:pers on' has invalid child element
'tnsperson:firs tname'. Expected 'firstname'. An error occurred at file
sample.xml, (4, 4).
*************** **

I make the validation using the code presented below. The 'filename' is
XML doc filename, 'SchemaURL' xsd filename and TargetNamespace has
http://vit.volvo.com/dept9272/2004/ESB as a value.

reader = new XmlTextReader(f ilename);
reader.Whitespa ceHandling=Whit espaceHandling. None;
// ^^-- to avoid problems when validating indented docs
XmlSchemaCollec tion xsc = null;
xsc = new XmlSchemaCollec tion();
xsc.Add(TargetN amespace, SchemaURL);

vreader = new XmlValidatingRe ader(reader);

vreader.Schemas .Add(xsc);

vreader.Validat ionEventHandler += new
ValidationEvent Handler(this.Va lidationCallbac k);

while (vreader.Read() )
{}

Why the parser expects child element from default namespace, when its
parent is declared as a reference from other namespace ?
Thanks in advance for any help. I'e spent two days browsing and
testing. No luck yet :-(

Nov 12 '05 #1
2 4557
Hi,

You need to put elementFormDefa ult="qualified" on your incr11.xsd schema.
Otherwise, all locally declared elements (like firstname, lastname, etc.)
are in NO namespace. In your sample instance document, they are in the
tnsperson namespace, because the default namespace declaration on the
"person" element applies to them.

So the error message makes sense - it is finding firstname in the tnsperson
namespace, when it is expecting to find firstname in no namespace.

Hope that helps,
Priscilla

------------------------------------------------------------------
Priscilla Walmsley
Author, Definitive XML Schema / XML in Office 2003
http://www.datypic.com
------------------------------------------------------------------

<to************ **@gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi !

I have problem with validating of the document with multiple
namespaces. The odd thing is, that my data work O'K when I test it
under XMLSpy but it doesn't work with my C# code.

My first 'main' schema is as follows:
incr2.xsd
----------
<xs:schema targetNamespace ="http://vit.volvo.com/dept9272/2004/ESB"
xmlns:p="tnsper son" xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefa ult="qualified" attributeFormDe fault="unqualif ied">
<xs:import namespace="tnsp erson" schemaLocation= "incr11.xsd "/>
<xs:element name="record">
<xs:complexTy pe >
<xs:sequence>
<xs:element ref="p:person"/>
<xs:element name="info" type="xs:string "/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

As you can see, it imports another schema,
incr11.xsd
----------
<xs:schema targetNamespace ="tnsperson" xmlns:t = "tnsperson"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexTy pe name="persontyp e">
<xs:sequence>
<xs:element name="firstname " type="xs:string "/>
<xs:element name="lastname" type="xs:string "/>
<xs:element name="age" type="xs:string "/>
</xs:sequence>
</xs:complexType>
<xs:element name="person" type="t:persont ype">
</xs:element>
</xs:schema>

The sample document is here:
sample.xml
-----------------
<?xml version="1.0" encoding="UTF-8"?>
<record xmlns="http://vit.volvo.com/dept9272/2004/ESB"
xmlns:p="tnsper son" >
<person xmlns="tnsperso n">
<firstname>To m</firstname>
<lastname>Rom </lastname>
<age>22</age>
</person>
<info>x_info</info>
</record>

The error message is as follows:
*************** **
The element 'tnsperson:pers on' has invalid child element
'tnsperson:firs tname'. Expected 'firstname'. An error occurred at file
sample.xml, (4, 4).
*************** **

I make the validation using the code presented below. The 'filename' is
XML doc filename, 'SchemaURL' xsd filename and TargetNamespace has
http://vit.volvo.com/dept9272/2004/ESB as a value.

reader = new XmlTextReader(f ilename);
reader.Whitespa ceHandling=Whit espaceHandling. None;
// ^^-- to avoid problems when validating indented docs
XmlSchemaCollec tion xsc = null;
xsc = new XmlSchemaCollec tion();
xsc.Add(TargetN amespace, SchemaURL);

vreader = new XmlValidatingRe ader(reader);

vreader.Schemas .Add(xsc);

vreader.Validat ionEventHandler += new
ValidationEvent Handler(this.Va lidationCallbac k);

while (vreader.Read() )
{}

Why the parser expects child element from default namespace, when its
parent is declared as a reference from other namespace ?
Thanks in advance for any help. I'e spent two days browsing and
testing. No luck yet :-(

Nov 12 '05 #2

Priscilla !!!

Thanks for your help !!!

Nov 12 '05 #3

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

Similar topics

25
3071
by: kj | last post by:
Consider the following XML document: <?xml version='1.0' encoding='UTF-8'?> <bar:foo xmlns:bar='someuri'> <baz/> </bar:foo> What namespace does baz belong to? What is this namespace bound to/associated with? My understanding was that baz above belongs to some "default default namespace", but I have not been able to
5
4071
by: Adam Child | last post by:
Hi All, I'm trying to validate an xml document. I'm having trouble setting the default namespace of the xml document. If I hard encode the namespace in the xml file then everything works fine. But I can't do this because it breaks our old tools which validate the xml to a dtd (error saying the dtd doens't allow xmlns attribute on the root element). So I'm trying to add the default namespace to the xml file by code. As follows:
2
1802
by: Jiri Netolicky | last post by:
Hi and happy new year to all. I have a problem with including external entities with namespace. I have this master xml wrapper file: <?xml version="1.0" ?> <!DOCTYPE log4j:eventSet SYSTEM "log4j.dtd"
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
8554
by: Plop69 | last post by:
need some help on following: xml file 1 <TEST xmlns="http://test" > <OK>mlkddflmkj</OK> </TEST>
2
3032
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a default namespace, Validate() just lets it slide through as a success. Is there a way to Validate() either a) mandating against a particular schema, or at the very least b) supplying a default namespace to be used even when not explicitly declared?
3
2937
by: George | last post by:
I am currently developing an xbrl validation software that takes an xml instance file and a lot of schemas(xsd files) and validates it against the xsd files. I am using Visual basic in visual studio 2005. I have managed to cycle through the xml file , validate most of the variables, however, i have some problems with the namespaces of some attributes. For example, in my xml instance file, it says: <xbrldi:typedMember...
13
2519
by: Axel Dahmen | last post by:
Hi, I've got a question on namespaces. After reading http://www.w3.org/TR/xml-names11 I still don't understand how namespaces are applied to attributes - particularly in regard to how processing applications are supposed to determine the proper validation DTD. In the following XML: ------------- <?xml version="1.0" ?>
3
3496
by: Jon | last post by:
I have an xml document like so... <?xml version="1.0" encoding="UTF-8"?> <rss version="2.0" xmlns:ng="http://newsgator.com/schema/extensions"> <channel> <title></title> <link></link> <description></description> ...
0
8428
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
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,...
1
8539
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
8630
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
7360
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
6181
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
5650
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();...
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.