473,696 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing with unqualified Namespace

I am both producing and parsing an xml document that needs to be validated against a schema. I wanted some consumers of the document
to have the option of not performing a validation, so I left the nodes in the instance unqualified. An example of the document is
below:

<?xml version="1.0" encoding="utf-8" ?>
<filingreceip t xmlns="http://www.disclosureu sa.org/filingreceipt.x sd">
<cpofilingnumbe r>TX20040430375 01</cpofilingnumber >
<receiptdate>20 04-05-01T16:54:21</receiptdate>
<zipfilebytes>9 5137</zipfilebytes>
<recipientcode> mactx</recipientcode>
</filingreceipt>
When the xmlns attribute is included in the document, I am able to use the XmlValidatingRe ader to validate the document. However,
parsing the document fails because the parser is looking for the prefix in the unqualified nodes, and I don't have a prefix to pass
to SelectSingleNod e. I don't want to qualify the nodes in the document to keep the document simple, and make validating optional. If
I remove the xmlns attribute, XmlValidatingRe ader refuses to validate the document.

I want to both validate and be able to parse this document, and don't know how to get both the validator and the parser to
cooperate.


Nov 12 '05 #1
4 2454
The XPath expression in SelectSingleNod e does not pick up the default
namespace of the xml document.

The following code sample shows how to make use of the namespace manager
that can be passed into SelectSingleNod e:
XmlDocument doc = new XmlDocument();
doc.Load("selec t.xml");
XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(doc.NameTa ble);
nsmgr.AddNamesp ace("tns", "http://www.disclosureu sa.org/filingreceipt.x sd");

XmlElement root = doc.DocumentEle ment;
XmlNode receiptdate = root.SelectSing leNode(".//tns:receiptdate ", nsmgr);
//You need to qualify the XPath with the namespace of the node that you are
trying to select.
Console.WriteLi ne(receiptdate. InnerText);

Also, to get no validation using XmlValidatingRe ader, you can set the
ValidationType property on the reader to ValdiationType. None

Thanks,
Priya

"Erik Moore" <er*******@aust in.rr.nospam.co m> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
I am both producing and parsing an xml document that needs to be validated against a schema. I wanted some consumers of the document to have the option of not performing a validation, so I left the nodes in the instance unqualified. An example of the document is below:

<?xml version="1.0" encoding="utf-8" ?>
<filingreceip t xmlns="http://www.disclosureu sa.org/filingreceipt.x sd">
<cpofilingnumbe r>TX20040430375 01</cpofilingnumber >
<receiptdate>20 04-05-01T16:54:21</receiptdate>
<zipfilebytes>9 5137</zipfilebytes>
<recipientcode> mactx</recipientcode>
</filingreceipt>
When the xmlns attribute is included in the document, I am able to use the XmlValidatingRe ader to validate the document. However, parsing the document fails because the parser is looking for the prefix in the unqualified nodes, and I don't have a prefix to pass to SelectSingleNod e. I don't want to qualify the nodes in the document to keep the document simple, and make validating optional. If I remove the xmlns attribute, XmlValidatingRe ader refuses to validate the document.
I want to both validate and be able to parse this document, and don't know how to get both the validator and the parser to cooperate.


Nov 12 '05 #2
> The following code sample shows how to make use of the namespace manager
that can be passed into SelectSingleNod e:


Thanks-
Is there a way to get the document to validate using the Validating reader without including the namespace declaration in the
instance document?

Nov 12 '05 #3
XmlValidatingRe ader will look for elements qualified with the
targetNamespace of the schema (if they are glboal elements or local elements
with form=qualified) that the xml is validated against.

If you do not want to declare namespaces in your xml, you should not have a
targetNamespace for the schema.

Thanks,
Priya

"Erik Moore" <er*******@aust in.rr.nospam.co m> wrote in message
news:eH******** ******@TK2MSFTN GP10.phx.gbl...
The following code sample shows how to make use of the namespace manager
that can be passed into SelectSingleNod e:
Thanks-
Is there a way to get the document to validate using the Validating

reader without including the namespace declaration in the instance document?

Nov 12 '05 #4

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 24/05/2004
Nov 12 '05 #5

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

Similar topics

0
4224
by: C. M. Sperberg-McQueen | last post by:
wooks (wookiz@hotmail.com) wrote: > <?xml version='1.0'?> > <userlogin xmlns="urn:faster:userlogin" > xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'> > <login>mick</login> > <password>brown</password> > </userlogin> > Above is my schema instance.
13
141243
by: Squid Seven | last post by:
This is just bizarre. for the following snippet of code: #include <string> using std::string; I get the error message:
6
1180
by: George Ter-Saakov | last post by:
I have XML in following format <ORDER> <HEADER> ... </HEADER> <LINE> ... <LINE> <LINE> ... <LINE> <LINE> ... <LINE> </ORDER> Can someone suggest how will i parseout such document using XmlSerializer and attributes.
9
6475
by: Mark Olbert | last post by:
I'm trying to serialize (using XmlSerializer.Serialize) a class that I generated from an XSD schema using XSD.EXE /c. The problem I'm running into is that the root element needs to be unqualified, and the default namespace needs to be included on it as an attribute. The schema I'm using is this: <xs:schema xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:html="http://www.w3.org/TR/REC-html40"...
7
92090
by: Warrax | last post by:
I am currently doing online tutorials for C++, and am pretty much stuck in a rut about this problem. It is saying that there's an expected unqualifed-id before '{' token (I will post the code in just a second) on line 11, and an expected ',' or ';' before '{' token also on line 11, however I don't have a clue what the first one means. The program is meant to save a user's name in a string variable within a structure, and to then show that name...
1
45758
by: Allen | last post by:
In my app, there is a namespace definition. .... namespace CMD { ... const int YT_UP = 1; // line 149 ... }; g++ tells expected unqualified-id before numeric constant error at
0
1779
by: Stef Mientki | last post by:
hello, I've syntax error which I totally don't understand: ########## mainfile : import test_upframe2 if __name__ == '__main__': var1 = 33 code = 'print var1 + 3 \n'
0
2997
by: Terry Reedy | last post by:
Stef Mientki wrote: Indendation is screwed. Is the above all do_more body? Which locals does this get you? __init__'s? (locals()?) Isn't this just the same as globals()?
9
27624
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic patterns(words). What it does is takes a string as a parameter, determines length of string, tests if the length is a perfect square, if it is then it makes a 2-d array with its length and height equal to the lengths root. If it isn't then it cuts it down to...
0
8592
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
9141
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
9005
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
8871
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
8846
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...
1
6512
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
5851
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
4605
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
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

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.