473,396 Members | 1,772 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,396 software developers and data experts.

SelectSingleNode when xmlns is an x-schema

I'm sorry if this has been asked and answered, I looked and didn't find this
particular situation so I have to ask.

If I understand correctly, the .NET XMLDOM must have an XmlNamespaceManager
bound even if the namespace doesn't have a name. (i.e. <TopNode
xmlns='www.microsoft.com'>)

And I've tried different configurations, nothing has helped. Here's a
sample XML doc:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
<TopLevel xmlns="x-schema:InfoSchema.xml">
<MyInfos>
<MyInfo>
<Type>TYPE_ONE</Type>
<Description>First Type</Description>
</MyInfo>
<MyInfo>
<Type>TYPE_TWO</Type>
<Description>Other Type</Description>
</MyInfo>
</MyInfos>
</TopLevel>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~

My code goes something like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
XmlDocument XMLDoc = new XmlDocument ();

XMLDoc.Load(XMLFilePath);

XmlNodeList MyInfos = XMLDoc.GetElementsByTagName("MyInfo");

foreach (XmlNode MyInfo in MyInfos)
{
XmlNode MyInfoType = MyInfo.SelectSingleNode("./Type"); //Doesn't Work

XmlNamespaceManager MyNsM = new XmlNamespaceManager(XMLDoc.NameTable);
MyNsM.AddNamespace("default", "x-schema:InfoSchema.xml");
XmlNode MyInfoType = MyInfo.SelectSingleNode("./default:Type");
//Doesn't Work

XmlNode MyInfoType = MyInfo.SelectSingleNode("//Type"); //Doesn't Work

XmlNode MyInfoType = MyInfo.SelectSingleNode("./*"); //Works but it's
not specific
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
How do I get the "Type" when I want it and the "Description" when I want it?

Thanks so much in advance for the help.

Tom P.
Dec 6 '05 #1
1 2201
Henry,

The documentation from AddNamespace states:

Parameters
prefix

The prefix to associate with the namespace being added. Use String.Empty
to add a default namespace.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Henry Padilla" <pa******@hotmail.com> wrote in message
news:e0******************@TK2MSFTNGP12.phx.gbl...
I'm sorry if this has been asked and answered, I looked and didn't find
this particular situation so I have to ask.

If I understand correctly, the .NET XMLDOM must have an
XmlNamespaceManager bound even if the namespace doesn't have a name.
(i.e. <TopNode xmlns='www.microsoft.com'>)

And I've tried different configurations, nothing has helped. Here's a
sample XML doc:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~
<TopLevel xmlns="x-schema:InfoSchema.xml">
<MyInfos>
<MyInfo>
<Type>TYPE_ONE</Type>
<Description>First Type</Description>
</MyInfo>
<MyInfo>
<Type>TYPE_TWO</Type>
<Description>Other Type</Description>
</MyInfo>
</MyInfos>
</TopLevel>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~

My code goes something like this:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
XmlDocument XMLDoc = new XmlDocument ();

XMLDoc.Load(XMLFilePath);

XmlNodeList MyInfos = XMLDoc.GetElementsByTagName("MyInfo");

foreach (XmlNode MyInfo in MyInfos)
{
XmlNode MyInfoType = MyInfo.SelectSingleNode("./Type"); //Doesn't
Work

XmlNamespaceManager MyNsM = new
XmlNamespaceManager(XMLDoc.NameTable);
MyNsM.AddNamespace("default", "x-schema:InfoSchema.xml");
XmlNode MyInfoType = MyInfo.SelectSingleNode("./default:Type");
//Doesn't Work

XmlNode MyInfoType = MyInfo.SelectSingleNode("//Type"); //Doesn't
Work

XmlNode MyInfoType = MyInfo.SelectSingleNode("./*"); //Works but it's
not specific
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~
How do I get the "Type" when I want it and the "Description" when I want
it?

Thanks so much in advance for the help.

Tom P.

Dec 6 '05 #2

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

Similar topics

1
by: Glenn Venzke | last post by:
I'm trying to invoke the "selectsinglenode" method on an XmlDocument object, but it doesn't seem able to find the node I want. I'm able to access the document root but when I try to parse an...
2
by: Edward Yang | last post by:
My XML document has a default namespace specified by xmlns="some_url". Here it is: <?xml version="1.0" encoding="utf-8" ?> <ssmproject name="sample" server="sql"...
7
by: Jason | last post by:
Hi I have an XML file i need to load and read the contents. Here is the top part of the xml file. <Research xsi:schemaLocation="http://www.rixml.org/2002/6/RIXML...
1
by: K. Wilder | last post by:
I'm trying to get the value of a single node using SelectSingleNode and I get the NullReference Error. Example: I want to get the URL in the HTML element but the GetHTMLPath() function fails on...
1
by: H Irick | last post by:
I have code that worked with an XMLDocument. Now I'm trying to convert it to use with a synchronized XML dataset loaded from my database. The only difference I can see is that the DataDocument...
6
by: David Thielen | last post by:
Hi; I am calling SelectSingleNode("/xml/s:Schema/s:ElementType/@name") where "/xml/s:Schema/s:ElementType/@name is a legit xpath statement (xml is the name of the rootnode) and that xpath...
3
by: Jonathan | last post by:
Hi, I use a XML-Doc with a Namespace like the following example: <HomedResources xmlns=http://schemas.microsoft.com/RtcServer/2002/11/dbimpexp Version="3"> <HomedResource...
1
by: Angela | last post by:
I am getting an error when I attempt to access a node with SelectSingleNode(): "The expression passed to this method should result in a NodeSet." I understand there is some confusion when you have...
19
by: David Thielen | last post by:
Hi; If there are no namespaces this works fine for me. But if the xml has namespaces, then I get either no node back or an exception. Here is the sample xml: <root xmlns="http://www.test.org"...
0
by: Martin | last post by:
Hi, I am using xmldocument.selectsinglenode to query an xml document. This works perfectly when the document to be queried has no namespace, however as some as i put a namespace in then null is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
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
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,...

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.