473,986 Members | 55,879 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.SelectSingl eNode("//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 1371
You need a XMLNameSpaceMan ager before you use SelectSingleNod e

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nsmgr.AddNamesp ace ("IL","urn:Issu eList");
xmlNode = xmlDoc.SelectSi ngleNode("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.SelectSingl eNode("//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 XMLNameSpaceMan ager before you use SelectSingleNod e

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(xmlDoc.Nam eTable);
nsmgr.AddNamesp ace ("IL","urn:Issu eList");
xmlNode = xmlDoc.SelectSi ngleNode("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.SelectSingl eNode("//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
2884
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") script_node_0.setAttribute("type", "text/javascript") script_node_0.setAttribute("src", "../test.js") minidom renders it as:
3
4774
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 of</br> inside it... Being <br/> HTML tags and not simple text like &lt;br/&gt;
2
1654
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
62629
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) I tried //title (doesn't work) I tried //title (doesn't work) Any suggestions welcome.
8
3713
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 it is empty or not. The above returns FALSE However, this:
0
1317
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> <FIELD> <DATA>c:\myfile.dat</DATA> </FIELD>
3
2501
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 code below it replace the <, and > with &lt; and &gt;. Thus it replaces IBM with: &lt;acronym title="International Business Machines"&gt;IBM&lt;/acronym&gt;
2
4679
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? "/my:MF/my:SVY/my:INSP/my:INA/my:IA/my:AN"; Thanks, Erin
3
13035
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 finding if an XML node is empty or if the node exist or doesn't exist. I'm searching the web, but got nothing yet. I was thinking of posting it here.
0
10204
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,...
0
11895
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
11476
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
10969
tracyyun
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...
0
10139
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...
0
7677
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
6626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3813
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.