473,695 Members | 3,241 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SelectNodes and Two XMLNS's in XML Root

Hi,

This is a newbie question to XMLNS. I just finished the article on "XML
Namespaces and How They Affect XPath and XSLT" by Dare Obasanjo and I'm
pretty sure I understand the problem. I just don't know how to achieve the
desired XPath result. I'm dealing with an XML document that has two XMLNS' in
the root node (Report) and I'm ending up with 0 results using SelectNodes. If
I take out both namespaces, the SelectNodes(XPa thQuery) works fine. With the
XMLNS' the SelectNodes(XPa thQuery, nsMgr) retrieves nothing. Here's a piece
of the XML doc and what I'm trying to do in code:

<?xml version="1.0"?>
<Report
xmlns="OESummar y_GTN"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" Name="OESummary _GTN"
Summary="Summar y of Order Number 5K129"
Advertiser="Poi nt 360-Dallas"
Estimate="ESTIM ATE 123"
Bill_To="Bernie Customer"
Job_Number="454 5454" >
<list1>
<list1_Details_ Group Name="Audio (3)">
<table1>
<table1_Group1_ Collection>
<table1_Group 1 code="KARN-AM" city_state="Lit tle Rock,AR">
<table1_Details _Group_Collecti on>
<table1_Details _Group stationType="AM " status="Online" />
</table1_Details_ Group_Collectio n>
</table1_Group1>
<table2>
<table2_Details _Group_Collecti on>
<table2_Details _Group isci="TLPEP0009 R" title="THEY'RE OFF/W. FLA" />
<table2_Details _Group isci="TLPEP0003 R" title="THEY'RE OFF/CEN FLA" />
</table2_Details_ Group_Collectio n>
</table2>
</list1_Details_G roup>
<list1_Details_ Group Name="Video Foo"> ...
</list1_Details_G roup>
</list1>
</report>

I know.....it's a really ugly document but that's what I have to work with!

Here's the code:

Dim xmlDoc As New XmlDocument
Dim OrderNodes, ISCINodes, StationNodes As XmlNodeList
Dim OrderNode, ISCINode, StationNode As XmlNode
Dim fileXML As New FileStream("c:\ temp\XMLDoc.xml ", FileMode.Open)
xmlDoc.Load(fil eXML)

Dim nsMgr As XmlNamespaceMan ager = New XmlNamespaceMan ager(xmlDoc.Nam eTable)
nsMgr.AddNamesp ace("", "OESummary_GTN" )
nsMgr.AddNamesp ace("xsi", "http://www.w3.org/2001/XMLSchema-instance")

' Get Order Detail Packets
OrderNodes = xmlDoc.GetEleme ntsByTagName("l ist1_Details_Gr oup")
For Each OrderNode In OrderNodes

' Pull Out ISCI's from Order Detail Packet
ISCINodes = OrderNode.Selec tNodes
("table2/table2_Details_ Group_Collectio n/table2_Details_ Group", nsMgr)

' Pull Out Stations from Order Detail Packet
StationNodes = OrderNode.Selec tNodes
("table1/table1_Group1_C ollection/table1_Group1", nsMgr)

next

I pretty sure the issue is related to the nsMgr, but I'm in the weeds as to
what SelectNodes is looking for, since none of the nested nodes has a
namespace. I assume they inherit from the root node and that they inherit the
default namespace??

Thanks!

Linda

Nov 12 '05 #1
2 2185
You have to use a dummy prefix. Change it to the following and it should
work:

nsMgr.AddNamesp ace("x", "OESummary_GTN" )

ISCINodes = OrderNode.Selec tNodes
("x:table2/x:table2_Detail s_Group_Collect ion/x:table2_Detail s_Group",
nsMgr)
"Linda Boumarafi" <Li************ @discussions.mi crosoft.com> wrote in
message news:97******** *************** ***********@mic rosoft.com...
Hi,

This is a newbie question to XMLNS. I just finished the article on "XML
Namespaces and How They Affect XPath and XSLT" by Dare Obasanjo and I'm
pretty sure I understand the problem. I just don't know how to achieve the
desired XPath result. I'm dealing with an XML document that has two XMLNS'
in
the root node (Report) and I'm ending up with 0 results using SelectNodes.
If
I take out both namespaces, the SelectNodes(XPa thQuery) works fine. With
the
XMLNS' the SelectNodes(XPa thQuery, nsMgr) retrieves nothing. Here's a
piece
of the XML doc and what I'm trying to do in code:

<?xml version="1.0"?>
<Report
xmlns="OESummar y_GTN"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance" Name="OESummary _GTN"
Summary="Summar y of Order Number 5K129"
Advertiser="Poi nt 360-Dallas"
Estimate="ESTIM ATE 123"
Bill_To="Bernie Customer"
Job_Number="454 5454" >
<list1>
<list1_Details_ Group Name="Audio (3)">
<table1>
<table1_Group1_ Collection>
<table1_Group 1 code="KARN-AM" city_state="Lit tle Rock,AR">
<table1_Details _Group_Collecti on>
<table1_Details _Group stationType="AM " status="Online" />
</table1_Details_ Group_Collectio n>
</table1_Group1>
<table2>
<table2_Details _Group_Collecti on>
<table2_Details _Group isci="TLPEP0009 R" title="THEY'RE OFF/W. FLA" />
<table2_Details _Group isci="TLPEP0003 R" title="THEY'RE OFF/CEN FLA" />
</table2_Details_ Group_Collectio n>
</table2>
</list1_Details_G roup>
<list1_Details_ Group Name="Video Foo"> ...
</list1_Details_G roup>
</list1>
</report>

I know.....it's a really ugly document but that's what I have to work
with!

Here's the code:

Dim xmlDoc As New XmlDocument
Dim OrderNodes, ISCINodes, StationNodes As XmlNodeList
Dim OrderNode, ISCINode, StationNode As XmlNode
Dim fileXML As New FileStream("c:\ temp\XMLDoc.xml ", FileMode.Open)
xmlDoc.Load(fil eXML)

Dim nsMgr As XmlNamespaceMan ager = New
XmlNamespaceMan ager(xmlDoc.Nam eTable)
nsMgr.AddNamesp ace("", "OESummary_GTN" )
nsMgr.AddNamesp ace("xsi", "http://www.w3.org/2001/XMLSchema-instance")

' Get Order Detail Packets
OrderNodes = xmlDoc.GetEleme ntsByTagName("l ist1_Details_Gr oup")
For Each OrderNode In OrderNodes

' Pull Out ISCI's from Order Detail Packet
ISCINodes = OrderNode.Selec tNodes
("table2/table2_Details_ Group_Collectio n/table2_Details_ Group", nsMgr)

' Pull Out Stations from Order Detail Packet
StationNodes = OrderNode.Selec tNodes
("table1/table1_Group1_C ollection/table1_Group1", nsMgr)

next

I pretty sure the issue is related to the nsMgr, but I'm in the weeds as
to
what SelectNodes is looking for, since none of the nested nodes has a
namespace. I assume they inherit from the root node and that they inherit
the
default namespace??

Thanks!

Linda

Nov 12 '05 #2
Awesome Chris, thanks! Worked perfectly!

Nov 12 '05 #3

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

Similar topics

7
2788
by: Robert Mark Bram | last post by:
Hi All! In the code below, I am reading in an xhtml document and attempting to use selectNodes to find a <p id="rmb"> node.. But the result is: 2 - */* 0 - */p Can anyone suggest what I am doing wrong?
2
5674
by: suresh | last post by:
Hi, I have the following xml file. <Navigator xmlns="urn:uuid:721DCCFA-8250-4820-8C7D- 7AF0E52305FD"> <SMDataSet RegionName="NA" CustomerName="ATT" MarketName="New Jersey" DataSetName="SMDS1" Technology="CDMA" StartDateAndTime="2003-06- 01T00:00:00.0000000-04:00" EndDate="2003-06-
5
7390
by: Alexander Gnauck | last post by:
Hello, i have problems with the Namespaces and the .Net XML Parser My XML looks like this: <query xmlns="jabber:iq:roster"> <item jid="srlee@localhost" name="srlee" subscription="both"><group>contacts</group></item> <item jid="tlee@localhost" name="Troy" subscription="both"><group>contacts</group></item>
2
6203
by: Dave | last post by:
Hi, Is there an easier way to pull a subset of nodes from one XmlDocument to another? I have the code below but would like to know if there is a more streamlined method. Thanks, Dave XmlNodeList nodeList = doc1.SelectNodes("//row"); foreach (XmlNode nodeCode in nodeList) { sb.Append(nodeCode.OuterXml);
3
8349
by: Steve | last post by:
I am getting no nodes from the following code: 'Put user code to initialize the page here Dim listService As New com.domain.my.Lists listService.Credentials = System.Net.CredentialCache.DefaultCredentials Dim xmlDoc = New System.Xml.XmlDocument Dim ndQuery As XmlNode = xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")
2
1758
by: Michael H | last post by:
Hello group, I have a some xml that looks like this below: <tuneRequests ct="3" xmlns:sql="urn:schemas-microsoft-com:xml-sql" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tr xsi:type="trGenericType" number="2">
3
6511
by: Stephen | last post by:
I have the following code that uses xquery to return search results from an xml doc. dim xmlString as string xmlString = "siteMapNode/siteMapNode/siteMapNode/siteMapNode" nodeList=root.SelectNodes(xmlString,nsmgr)
0
2413
by: Karel Kral | last post by:
Hello, I have created simple COM service in .NET. COM is accessed from another not NET application by late binding call. And the problem: If I call NetComClass.Hello from another .NET code, all works fine. But when calling from COM, the program hangs at line nodeList = root.SelectNodes("/bookstore/book"). CPU is utilized 100%. Briefly: XmlDocument.SelectNodes call hangs EVERY TIME when selected nodes count is greater than 0. I have...
1
2445
by: Jazper | last post by:
hi i have a problem querying a simple atom-feed by xpath using the XmlDocument. i'm googleing for hours now and can't get a solution: --- Code --- XmlDocument doc = new XmlDocument(); doc.Load(XmlReader.Create(_feed.AbsoluteUri)); XmlNodeList list = doc.SelectNodes("feed"); // list.Count is always 0
0
8582
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
9122
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...
1
8860
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
8832
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
7672
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
6498
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
4348
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3018
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
2281
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.