473,396 Members | 1,891 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,396 software developers and data experts.

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 2759
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
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
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
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
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
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
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
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
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
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.