473,796 Members | 2,509 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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" ?>
- <BackgroundRepo rts xmlns="http://ns.hr-xml.org/2004-08-02" userId=""
password="">
- <BackgroundRepo rtPackage type="report">
- <ProviderRefere nceId>
<IdValue>717351 1</IdValue>
</ProviderReferen ceId>
</BackgroundRepor tPackage>
</BackgroundRepor ts>

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

e.g.

Dim objXmlDoc As New XmlDocument
Dim objXmlNode As XmlNode
objXmlDoc.LoadX ml(sXML)
objXmlNode = objXmlDoc.Selec tSingleNode("//BackgroundRepor tPackage")

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

Dec 28 '05 #1
2 2141
Solved it:

Use the XmlNameSpaceMan ager object

Dim nsmgr As XmlNamespaceMan ager = New
XmlNamespaceMan ager(objXmlDoc. NameTable)
nsmgr.AddNamesp ace(String.Empt y, "http://ns.hr-xml.org/2004-08-02")
objXmlNode = objXmlDoc.Selec tSingleNode("//BackgroundRepor tPackage")

Dec 28 '05 #2
Code correction:

nsmgr = New XmlNamespaceMan ager(objXmlDoc. NameTable)
nsmgr.AddNamesp ace("ns1", "http://ns.hr-xml.org/2004-08-02")
Dim root As XmlElement = objXmlDoc.Docum entElement
oNode = root.SelectSing leNode("//ns1:BackgroundR eportPackage", nsmgr)

Dec 28 '05 #3

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

Similar topics

4
2462
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 nodes in the instance unqualified. An example of the document is below: <?xml version="1.0" encoding="utf-8" ?> <filingreceipt xmlns="http://www.disclosureusa.org/filingreceipt.xsd"> <cpofilingnumber>TX2004043037501</cpofilingnumber>...
6
7811
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 statement works fine on the document in XmlSpy. However, when I call this is .NET 1.1, I get the following exception: XPathException {"Namespace Manager or XsltContext needed. This query has a
4
4128
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" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:myurl-org:ns2 ...\Schemas\schema.xsd" type="Message"> <id root="7DC0FFE7-1224-4598-8F20-3B7662D416A1"/>
7
18148
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 ng_unit></assigned_bargaining_unit><assigned_department></assigned_departmen t><assigned_locations><assigned_location></assigned_location></assigned_loca tions><assigned_position></assigned_position><assigned_position_department><...
2
1415
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 client. I never would have thought of it, but someone in our group had heard that using XmlDocument.Load (Server.MapPath (file)); was slower than actually creating the stream, the XmlTextReader, and passing the reader to the XmlDocument.Load();.
3
27063
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 = new XmlDocument(); XmlElement el = doc.CreateElement("foo:data"); doc.AppendChild(el); doc.Save("foo.xml");
7
6716
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 its not working. Any suggstions? Kashif
1
2462
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'> <subElement>Value</subElement> </rootObject> The 'http://company.com/root.xsd' doesn't actually exist, but I didn't think that mattered.. I have some utility functions that I use to help me
4
2013
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. My question is, the XML stream that's coming back is telling if it's a successful license registration, validation, too many installs etc. How do I capture that information and use in my logic? I tried:
0
9680
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10456
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...
0
10230
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9052
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
7548
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
6788
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();...
0
5442
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...
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2926
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 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...

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.