473,761 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot find the p node with selectNodes

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[@id = "rmb"]

Can anyone suggest what I am doing wrong?

Any ideas would be most appreciated!

Rob
:)
====
xmlTest.asp
====
<%@LANGUAGE="JA VASCRIPT" CODEPAGE="1252" %>
<%

var xmlDocument = Server.CreateOb ject("Msxml2.DO MDocument.3.0") ;
xmlDocument.asy nc = false;
xmlDocument.set Property ("ServerHTTPReq uest", true);
xmlDocument.set Property ("SelectionLang uage", "XPath");
var loaded = xmlDocument.loa d(Server.MapPat h("basic.htm")) ;

if (loaded)
{
var editable = xmlDocument.sel ectNodes ("*/*");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");

var editable = xmlDocument.sel ectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");
} // end if

%>

====
basic.htm
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Heading</h1>
<p>Body Text</p>
<p id="rmb">Body Text</p>
</body>
</html>
Jul 19 '05 #1
7 2794
Try:

//p[@id='rmb']

Chris.
"Robert Mark Bram" <none> wrote in message
news:40******** *************** @news.optusnet. com.au...
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[@id = "rmb"]

Can anyone suggest what I am doing wrong?

Any ideas would be most appreciated!

Rob
:)
====
xmlTest.asp
====
<%@LANGUAGE="JA VASCRIPT" CODEPAGE="1252" %>
<%

var xmlDocument = Server.CreateOb ject("Msxml2.DO MDocument.3.0") ;
xmlDocument.asy nc = false;
xmlDocument.set Property ("ServerHTTPReq uest", true);
xmlDocument.set Property ("SelectionLang uage", "XPath");
var loaded = xmlDocument.loa d(Server.MapPat h("basic.htm")) ;

if (loaded)
{
var editable = xmlDocument.sel ectNodes ("*/*");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");

var editable = xmlDocument.sel ectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");
} // end if

%>

====
basic.htm
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Heading</h1>
<p>Body Text</p>
<p id="rmb">Body Text</p>
</body>
</html>

Jul 19 '05 #2
Try
//*[name(.) = 'p' and @id = 'rmb'

Cheers

Pravin Pati
Microsoft(R) MVP
Jul 19 '05 #3
Hi Chris,

Thank you for the response.
//p[@id='rmb']


This did not work.. it gave me:
0 - //p[@id='rmb']

I am at a loss to explain why. :-\

Rob
:)
Jul 19 '05 #4
Hi Pravin,

Thank you very much - this worked!
//*[name(.) = 'p' and @id = 'rmb']


The result I obtained:
0 - //p[@id='rmb']
1 - //*[name(.) = 'p' and @id = 'rmb']

Do you happend to know why the first one (Chris Barber's suggestion) deosn't
work for me?

Thank you again!

Rob
:)
Jul 19 '05 #5
Post a real (eg. XML validating XHTML document that shows this issue so I
can run it in Xselerator). There is no reason why the Xpath I posted should
not work unless your XHTML is a bit funky (eg. namespaces etc., DOM type, or
the method of executing the XPath statement).

This XML:

<?xml version="1.0"?>
<root>
<p id="rmb"/>
</root>

And this XSLT:

<?xml version="1.0"?>
<xsl:styleshe et version="1.0"
xmlns:xsl="http ://www.w3.org/1999/XSL/Transform">
<xsl:template match="//p[@id='rmb']">
<p>Found the node</p>
</xsl:template>
</xsl:stylesheet>

Produce:

<?xml version="1.0" encoding="UTF-16"?>
<p>Found the node</p>

Proving that the XPath works (at least in XSLT implementation which should
be identical to selectSingleNod e implementation.

As a test, the following html client side Javascript gave an alert box
showing the selected node XML indicating that the node was found.

<html>
<head>
</head>
<body>

<script language="Javas cript">

var pobjXML = new ActiveXObject(" Msxml2.DOMDocum ent.4.0");
pobjXML.async = false;
pobjXML.load("m ydoc.xml");
alert("XML document is: " + pobjXML.xml);
var pstrXPath = "//p[@id='rmb']";
alert("XPath is: " + pstrXPath);
var pobjNode = pobjXML.selectS ingleNode(pstrX Path);
if (pobjNode){
alert("Selected node xml is: " + pobjNode.xml);
}
else{
alert('Node not found');
}

</script>
<p>Test completed</p>
</body>
</html>

Chris.

"Chris Barber" <ch***@blue-canoe.co.uk.NOS PAM> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
Try:

//p[@id='rmb']

Chris.
"Robert Mark Bram" <none> wrote in message
news:40******** *************** @news.optusnet. com.au...
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[@id = "rmb"]

Can anyone suggest what I am doing wrong?

Any ideas would be most appreciated!

Rob
:)
====
xmlTest.asp
====
<%@LANGUAGE="JA VASCRIPT" CODEPAGE="1252" %>
<%

var xmlDocument = Server.CreateOb ject("Msxml2.DO MDocument.3.0") ;
xmlDocument.asy nc = false;
xmlDocument.set Property ("ServerHTTPReq uest", true);
xmlDocument.set Property ("SelectionLang uage", "XPath");
var loaded = xmlDocument.loa d(Server.MapPat h("basic.htm")) ;

if (loaded)
{
var editable = xmlDocument.sel ectNodes ("*/*");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");

var editable = xmlDocument.sel ectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.lengt h + " - " + editable.expr + "<br>");
} // end if

%>

====
basic.htm
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Heading</h1>
<p>Body Text</p>
<p id="rmb">Body Text</p>
</body>
</html>


Jul 19 '05 #6
Hi Chis!
Post a real (eg. XML validating XHTML document that shows this issue so I
can run it in Xselerator).


Maybe I misunderstand you, but basic.htm is valid and correct XML -
Dreamweaver and XML Spy both validate the document..

Rob
:)

====
basic.htm
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Heading</h1>
<p>Body Text</p>
<p id="rmb">Body Text</p>
</body>
</html>
Jul 19 '05 #7
Your namespace on html element will be preventing my XPath from operating in
an XMLDOM environment.

Have a read about 'default namespaces' when using XPath statements to select
nodes.

I think that the XPath Pravin provided may be namespace insensitive?

Chris.

"Robert Mark Bram" <none> wrote in message
news:40******** **************@ news.optusnet.c om.au...
Hi Chis!
Post a real (eg. XML validating XHTML document that shows this issue so I
can run it in Xselerator).


Maybe I misunderstand you, but basic.htm is valid and correct XML -
Dreamweaver and XML Spy both validate the document..

Rob
:)

====
basic.htm
====
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitl ed Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Heading</h1>
<p>Body Text</p>
<p id="rmb">Body Text</p>
</body>
</html>

Jul 19 '05 #8

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

Similar topics

2
1515
by: Steve Jorgensen | last post by:
Working with the DOM (specifically, the MSXML DOM), I'm wondering if there's an efficient way to check whether it would be matched by a given XPath expression. I've made it work to just run the XPath select on the document, looping through all the nodes returned, and seeing if one of those is the same as the node in question. If I need to check many expressions, though, this would not be efficient.
8
488
by: chris yoker via DotNetMonster.com | last post by:
hiya, I succesfully return a "nodeList" thru the "xmlDoc.SelectNodes" method. This nodeList is taken from a repetitive, uniform xml doc. I can successfully append a child node at the correct position using the following code: <code> <!--Node successfully inserted into corrrect position in nodeList(0)--> nodeList(0).InsertAfter(additionalNode, nodeList(0).ChildNodes(5))
3
1208
by: chris yoker via DotNetMonster.com | last post by:
hi, I have an xmlFile <code> <rows> <row> <PRODUCT-TYPE>bike</PRODUCT-TYPE> <PRODUCT-DATE>01/01/2004</PRODUCT-DATE> <ADDED-NODE>"blah"<ADDED-NODE /> </row>
4
5540
by: ryu | last post by:
Hi all, I have a xml document where I have to replace the value of node type that is text. For example, if the value of a node whose type is 'text' is 'Toyota', I would like it to be replaced with 'Honda'. Is there a way to do this?
3
4860
by: Sharon | last post by:
I'm trying to navigate inside an XML file that has a very simple namespace, But when I'm using the name space a get nothing (Count == 0) when I do SelectNodes() or SelectSingleNode() (null). When I remove the namespace from the XML file and from the code --> the Select is successful but I do need to leave the namespace in the XML file. Here is the XML file I'm using: <?xml version="1.0" standalone="yes"?> <MyDB xmlns="DataBase.xsd">...
16
3529
by: TT (Tom Tempelaere) | last post by:
Hi all, I created an XSD to define the structure of an XML file for my project. I made an XML file linked to the XSD using XmlSpy. The problem is that if I read the file using .NET XmlDocument and then query for the root element, the result is always null (1). However if I strip the root element of all attributes generated by XmlSpy, then there is no problem to find the root element with .NET XML classes (2). (1) The XML for which...
4
6495
by: MA | last post by:
Hi, How to access the total number of child nodes from a parent node. For example, I would like to get the total number of child nodes from <parent1and <parent2node. The SelectNodes method return the total number of <foldernodes (9) regardless of calling from the <parent1> and <parent2node. XML: ----------------------------------
0
1730
by: Kavitha Sudhershan | last post by:
hi, i wanna read the node values from xml. As per my code i can read the node values in first child node and for the next node am not able to read the node values. pls help me. i'll paste the code below: Sub readfile() objxmldom.async = False objxmldom.Load ("D:\CRT\rules\AQUA.xml")
4
1876
by: =?Utf-8?B?VG9yZW4gVmFsb25l?= | last post by:
Was editing code, am getting the following errors } expected Type or namespace definition, or end-of-file expected Eyes crossed cannot find code below! using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing;
0
9554
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
9377
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
10136
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
9989
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...
1
9925
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,...
0
9811
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
8814
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
6640
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
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.