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 2 2182
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
Awesome Chris, thanks! Worked perfectly! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
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-
|
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>
|
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);
|
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", "")
| |
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">
|
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)
|
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...
|
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
|
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,...
|
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...
| |
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,...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |