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