473,324 Members | 2,257 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,324 software developers and data experts.

Replace Empty Node

I'm trying to use XPath to get a handle on one specific node so that I can
replace it with an xml fragment I've loaded from another file.

So if I have this XML:

<issue>
<id>1</id>
<date>7/28/2006</date>
<states/>
</issue>

If "myDoc" is the preceding XML loaded into an XmlDocument object, then this
code is what I want to return the <states/node above, but it returns null
instead:

XmlNode statesNode = doc.SelectSingleNode("//states");

I can't seem to get this XPath to return a node. Can someone help me out
here? Is there a better approach?
Jul 28 '06 #1
2 1342
You need a XMLNameSpaceManager before you use SelectSingleNode

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace ("IL","urn:IssueList");
xmlNode = xmlDoc.SelectSingleNode("issue/states", nsmgr);

Also, if this does not return an empty string, then try including
<states></states>
instead of <states/>

Hope this helps
Ramya
Todd Price wrote:
I'm trying to use XPath to get a handle on one specific node so that I can
replace it with an xml fragment I've loaded from another file.

So if I have this XML:

<issue>
<id>1</id>
<date>7/28/2006</date>
<states/>
</issue>

If "myDoc" is the preceding XML loaded into an XmlDocument object, then this
code is what I want to return the <states/node above, but it returns null
instead:

XmlNode statesNode = doc.SelectSingleNode("//states");

I can't seem to get this XPath to return a node. Can someone help me out
here? Is there a better approach?
Aug 1 '06 #2
That was it! I had been having complications with another issue due to
namespaces, and this cleared that up as well. Thanks!

"Ramya A" wrote:
You need a XMLNameSpaceManager before you use SelectSingleNode

XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsmgr.AddNamespace ("IL","urn:IssueList");
xmlNode = xmlDoc.SelectSingleNode("issue/states", nsmgr);

Also, if this does not return an empty string, then try including
<states></states>
instead of <states/>

Hope this helps
Ramya
Todd Price wrote:
I'm trying to use XPath to get a handle on one specific node so that I can
replace it with an xml fragment I've loaded from another file.

So if I have this XML:

<issue>
<id>1</id>
<date>7/28/2006</date>
<states/>
</issue>

If "myDoc" is the preceding XML loaded into an XmlDocument object, then this
code is what I want to return the <states/node above, but it returns null
instead:

XmlNode statesNode = doc.SelectSingleNode("//states");

I can't seem to get this XPath to return a node. Can someone help me out
here? Is there a better approach?

Aug 1 '06 #3

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

Similar topics

4
by: Derek Basch | last post by:
Hello All, I ran into a problem while dynamically constructing XHTML documents using minidom. If you create a script tag such as: script_node_0 = self.doc.createElement("script")...
3
by: Miguel J. Jiménez | last post by:
Hi, I have the following node: <node> Some text here with lots of inside it... </node> and I would like it to transfrom it using XSLT to the following: Some text<br/> here with</br> lots...
2
by: Victor | last post by:
While debugging my stylesheet using XMLSpy, I got a really weird result: <xsl:if test="$match = true()"> matches even if $match is an empty node fragment. How can this be? -- Victor
4
by: n_o_s_p_a__m | last post by:
My xml doc has many <title></title> and <title> in it, meaning the nodes have no content (although some do). How can I test for this? I tried title (doesn't work) I tried //title (doesn't work)...
8
by: darrel | last post by:
I have a when statement: <xsl:when test="//pageTitle = not(string(.))"> This should find the 'pageTitle' node that has a sibling of 'linkID' that matches the '$activeLink' parameter and see if...
0
by: Philip Wagenaar | last post by:
I have an XML file that will contain the data of a binary file in MIME encoding. My application receiver the XML file with the location of the binary file: <REQUEST> <IMPORT> <DOCUMENT>...
3
by: gregpinero | last post by:
Hi guys, What I'm trying to do is find all instances of an acronymn such as IBM on a webpage and replace it with <acronym title="International Business Machines">IBM</acronym>. However in my...
2
by: esebastian | last post by:
Hi all, Basically i want to do get the specific node that is empty but when i try the following i get a null node even though I know there is a node whose AN value is null. What am i doing wrong?...
3
by: SM | last post by:
I think that simpleXML is the best thing i've seen in PHP5. It's so simple (d'ho!) and easy to use when it comes to reading a simple XML file. The only thing i'm not sure how to achieve is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.