XPath, XML and other

D

David

hello, i have XmlDocument with InnerXML property returnig this (xhtml))

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title />
</head>
<body />
</html>

....now, i calling its SelecetSingleNode method, like this
..SelectSingleNode("/html/body");

but i get null value in return...

....what is wrong?

also tried:

..SelectSingleNode("/html/body[1]")

..SelectSingleNode("//body")

with same result...



thanx, David
 
J

Jon Skeet [C# MVP]

David said:
hello, i have XmlDocument with InnerXML property returnig this (xhtml))

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"[]>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title />
</head>
<body />
</html>

...now, i calling its SelecetSingleNode method, like this
.SelectSingleNode("/html/body");

but i get null value in return...

...what is wrong?

You need to use a namespace manager, eg:

XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("x", "http://www.w3.org/1999/xhtml");
Console.WriteLine (doc.SelectSingleNode("/x:html/x:body", nsMgr));

Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top