473,508 Members | 2,367 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(XPathQuery) works fine. With the
XMLNS' the SelectNodes(XPathQuery, 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="OESummary_GTN"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="OESummary_GTN"
Summary="Summary of Order Number 5K129"
Advertiser="Point 360-Dallas"
Estimate="ESTIMATE 123"
Bill_To="Bernie Customer"
Job_Number="4545454" >
<list1>
<list1_Details_Group Name="Audio (3)">
<table1>
<table1_Group1_Collection>
<table1_Group1 code="KARN-AM" city_state="Little Rock,AR">
<table1_Details_Group_Collection>
<table1_Details_Group stationType="AM" status="Online" />
</table1_Details_Group_Collection>
</table1_Group1>
<table2>
<table2_Details_Group_Collection>
<table2_Details_Group isci="TLPEP0009R" title="THEY'RE OFF/W. FLA" />
<table2_Details_Group isci="TLPEP0003R" title="THEY'RE OFF/CEN FLA" />
</table2_Details_Group_Collection>
</table2>
</list1_Details_Group>
<list1_Details_Group Name="Video Foo"> ...
</list1_Details_Group>
</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(fileXML)

Dim nsMgr As XmlNamespaceManager = New XmlNamespaceManager(xmlDoc.NameTable)
nsMgr.AddNamespace("", "OESummary_GTN")
nsMgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")

' Get Order Detail Packets
OrderNodes = xmlDoc.GetElementsByTagName("list1_Details_Group")
For Each OrderNode In OrderNodes

' Pull Out ISCI's from Order Detail Packet
ISCINodes = OrderNode.SelectNodes
("table2/table2_Details_Group_Collection/table2_Details_Group", nsMgr)

' Pull Out Stations from Order Detail Packet
StationNodes = OrderNode.SelectNodes
("table1/table1_Group1_Collection/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 2167
You have to use a dummy prefix. Change it to the following and it should
work:

nsMgr.AddNamespace("x", "OESummary_GTN")

ISCINodes = OrderNode.SelectNodes
("x:table2/x:table2_Details_Group_Collection/x:table2_Details_Group",
nsMgr)
"Linda Boumarafi" <Li************@discussions.microsoft.com> wrote in
message news:97**********************************@microsof t.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(XPathQuery) works fine. With
the
XMLNS' the SelectNodes(XPathQuery, 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="OESummary_GTN"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="OESummary_GTN"
Summary="Summary of Order Number 5K129"
Advertiser="Point 360-Dallas"
Estimate="ESTIMATE 123"
Bill_To="Bernie Customer"
Job_Number="4545454" >
<list1>
<list1_Details_Group Name="Audio (3)">
<table1>
<table1_Group1_Collection>
<table1_Group1 code="KARN-AM" city_state="Little Rock,AR">
<table1_Details_Group_Collection>
<table1_Details_Group stationType="AM" status="Online" />
</table1_Details_Group_Collection>
</table1_Group1>
<table2>
<table2_Details_Group_Collection>
<table2_Details_Group isci="TLPEP0009R" title="THEY'RE OFF/W. FLA" />
<table2_Details_Group isci="TLPEP0003R" title="THEY'RE OFF/CEN FLA" />
</table2_Details_Group_Collection>
</table2>
</list1_Details_Group>
<list1_Details_Group Name="Video Foo"> ...
</list1_Details_Group>
</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(fileXML)

Dim nsMgr As XmlNamespaceManager = New
XmlNamespaceManager(xmlDoc.NameTable)
nsMgr.AddNamespace("", "OESummary_GTN")
nsMgr.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")

' Get Order Detail Packets
OrderNodes = xmlDoc.GetElementsByTagName("list1_Details_Group")
For Each OrderNode In OrderNodes

' Pull Out ISCI's from Order Detail Packet
ISCINodes = OrderNode.SelectNodes
("table2/table2_Details_Group_Collection/table2_Details_Group", nsMgr)

' Pull Out Stations from Order Detail Packet
StationNodes = OrderNode.SelectNodes
("table1/table1_Group1_Collection/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
2769
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...
2
5665
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"...
5
7374
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"...
2
6186
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 ...
3
8341
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 =...
2
1746
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...
3
6501
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"...
0
2395
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...
1
2422
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();...
0
7224
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,...
0
7380
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...
1
7039
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...
0
5626
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,...
1
5050
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...
0
4706
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...
0
3192
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...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.