473,399 Members | 3,401 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,399 software developers and data experts.

Parsing an XmlDocument with a namespace

Hello All,

I have the following xml file: which I read into a string (sXML)

<?xml version="1.0" ?>
- <BackgroundReports xmlns="http://ns.hr-xml.org/2004-08-02" userId=""
password="">
- <BackgroundReportPackage type="report">
- <ProviderReferenceId>
<IdValue>7173511</IdValue>
</ProviderReferenceId>
</BackgroundReportPackage>
</BackgroundReports>

I am trying to use the xmldocument.selectsinglenode function to extract
node values

e.g.

Dim objXmlDoc As New XmlDocument
Dim objXmlNode As XmlNode
objXmlDoc.LoadXml(sXML)
objXmlNode = objXmlDoc.SelectSingleNode("//BackgroundReportPackage")

If I remove the xmlns spec, this code works fine...how do I use
SelectSingleNode in conjunction with a namespace ?
Thanks In Advance

Dec 28 '05 #1
2 2096
Solved it:

Use the XmlNameSpaceManager object

Dim nsmgr As XmlNamespaceManager = New
XmlNamespaceManager(objXmlDoc.NameTable)
nsmgr.AddNamespace(String.Empty, "http://ns.hr-xml.org/2004-08-02")
objXmlNode = objXmlDoc.SelectSingleNode("//BackgroundReportPackage")

Dec 28 '05 #2
Code correction:

nsmgr = New XmlNamespaceManager(objXmlDoc.NameTable)
nsmgr.AddNamespace("ns1", "http://ns.hr-xml.org/2004-08-02")
Dim root As XmlElement = objXmlDoc.DocumentElement
oNode = root.SelectSingleNode("//ns1:BackgroundReportPackage", nsmgr)

Dec 28 '05 #3

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

Similar topics

4
by: Erik Moore | last post by:
I am both producing and parsing an xml document that needs to be validated against a schema. I wanted some consumers of the document to have the option of not performing a validation, so I left the...
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...
4
by: Mike [MCP VB] | last post by:
Hi, I hope this is the right place to ask. I have an xml file thus: <?xml version="1.0" encoding="UTF-8"?> <Message xmlns="urn:myurl-org:ns2"...
7
by: wk6pack | last post by:
Hi, I would like to know how to parse the following xml string using vb.net? currxml=" <employee><address_2></address_2><assignments><assignment><assigned_bargaini...
2
by: Mark | last post by:
Hi... We've been doing some basic performance testing comparing asp, asp.net, mono, and php. One of the basic tests is on simply parsing an xml document and streaming the result back to the...
3
by: Andy Fish | last post by:
Hi, I am creating a new XmlDocument from scratch, but I can't see how I can make a namespace declaration and associate a prefix with it. For instance in the following example: XmlDocument doc...
7
by: kashaziz | last post by:
Hello, I am here after head-banging with this issue for several days. I am trying to parse a feed using JS and have stucked on the <content:encoded> tag. I have tried getElementsbyTagName but...
1
by: Michael Bray | last post by:
I have some XML that is being generated by an external component and structurally looks like this: <?xml version='1.0' ?> <rootObject xmlns='http://company.com/root.xsd'>...
4
by: eSolTec, Inc. 501(c)(3) | last post by:
Thank you in advance for any and all assistance. It is greatly appreciated. I am working with Plimus for licensing my software. I can communicate with the server and I'm getting responses in XML....
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
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
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
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
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,...
0
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...

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.