473,489 Members | 2,492 Online
Bytes | Software Development & Data Engineering Community
Create 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="JAVASCRIPT" CODEPAGE="1252"%>
<%

var xmlDocument = Server.CreateObject("Msxml2.DOMDocument.3.0");
xmlDocument.async = false;
xmlDocument.setProperty ("ServerHTTPRequest", true);
xmlDocument.setProperty ("SelectionLanguage", "XPath");
var loaded = xmlDocument.load(Server.MapPath("basic.htm"));

if (loaded)
{
var editable = xmlDocument.selectNodes ("*/*");
Response.write (editable.length + " - " + editable.expr + "<br>");

var editable = xmlDocument.selectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.length + " - " + 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 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 2764
Try:

//p[@id='rmb']

Chris.
"Robert Mark Bram" <none> wrote in message
news:40***********************@news.optusnet.com.a u...
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="JAVASCRIPT" CODEPAGE="1252"%>
<%

var xmlDocument = Server.CreateObject("Msxml2.DOMDocument.3.0");
xmlDocument.async = false;
xmlDocument.setProperty ("ServerHTTPRequest", true);
xmlDocument.setProperty ("SelectionLanguage", "XPath");
var loaded = xmlDocument.load(Server.MapPath("basic.htm"));

if (loaded)
{
var editable = xmlDocument.selectNodes ("*/*");
Response.write (editable.length + " - " + editable.expr + "<br>");

var editable = xmlDocument.selectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.length + " - " + 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 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:stylesheet 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 selectSingleNode 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="Javascript">

var pobjXML = new ActiveXObject("Msxml2.DOMDocument.4.0");
pobjXML.async = false;
pobjXML.load("mydoc.xml");
alert("XML document is: " + pobjXML.xml);
var pstrXPath = "//p[@id='rmb']";
alert("XPath is: " + pstrXPath);
var pobjNode = pobjXML.selectSingleNode(pstrXPath);
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.NOSPAM> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Try:

//p[@id='rmb']

Chris.
"Robert Mark Bram" <none> wrote in message
news:40***********************@news.optusnet.com.a u...
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="JAVASCRIPT" CODEPAGE="1252"%>
<%

var xmlDocument = Server.CreateObject("Msxml2.DOMDocument.3.0");
xmlDocument.async = false;
xmlDocument.setProperty ("ServerHTTPRequest", true);
xmlDocument.setProperty ("SelectionLanguage", "XPath");
var loaded = xmlDocument.load(Server.MapPath("basic.htm"));

if (loaded)
{
var editable = xmlDocument.selectNodes ("*/*");
Response.write (editable.length + " - " + editable.expr + "<br>");

var editable = xmlDocument.selectNodes ("*/p[@id = \"rmb\"]");
Response.write (editable.length + " - " + 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 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.com.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.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled 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
1493
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...
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...
3
1194
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
5524
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...
3
4841
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...
16
3493
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...
4
6459
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...
0
1714
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...
4
1858
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...
0
7108
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
6967
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
7181
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
7352
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...
0
5445
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,...
1
4875
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...
0
4565
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...
1
618
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
272
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...

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.