all groups > dotnet xml > may 2006 >
You're in the

dotnet xml

group:

Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ?


Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? Daniel
5/23/2006 5:43:49 PM
dotnet xml: Is it possible to use regular expressions inside of an xpath statement
executed by System.Xml.XmlDocument.SelectSingleNode() ?

string sdoc = "<foo><bar a='1'/><bar a='2'/></foo>";
System.Xml.XmlDocument pdoc = new System.Xml.XmlDocument();
pdoc.LoadXml(sdoc);
System.Xml.XmlNode pnode =
pdoc.SelectSingleNode("//foo/bar/matches(.,'\\d')");
string foo = pnode.InnerText;
int i23 = 23 + 23;

Re: Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? Oleg Tkachenko [MVP]
5/24/2006 5:45:55 PM
[quoted text, click to view]

Yes, when using EXSLT.NET. See
http://msdn.microsoft.com/xml/default.aspx?pull=/library/en-us/dnxml/html/practexslt.asp#practexslt_topic4

--
Oleg Tkachenko [XML MVP, MCAD]
Re: Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? Oleg Tkachenko [MVP]
5/24/2006 5:47:11 PM
[quoted text, click to view]

Forgot to mention that latest EXSLT.NET version can found at
http://www.xmlmvp.org/exslt.

--
Oleg Tkachenko [XML MVP, MCAD]
Re: Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? Daniel
5/24/2006 6:23:35 PM
EXSLT.NET has nothing to support regular expressions inside of xpath for
System.Xml.XmlNode xpath methods such as SelectNodes or SelectSingleNode

http://msdn.microsoft.com/xml/default.aspx?pull=/library/en-us/dnxml/html/practexslt.asp#practexslt_topic4


[quoted text, click to view]

Re: Is it possible to use regular expressions inside of an xpath statement executed by System.Xml.XmlDocument.SelectSingleNode() ? Oleg Tkachenko [MVP]
5/25/2006 1:00:46 PM
[quoted text, click to view]

These methods are just wrappers around XPathNavigator.Select() method
and you are right, they are useless with EXSLT.NET. Use XPathNavigator
instead. Here is a sample how to use EXSLT function with XmlDocument and
XPath.

XmlDocument doc = new XmlDocument();
doc.Load("foo.xml");
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("set:distinct(//@country)");
expr.SetContext(new ExsltContext(doc.NameTable));
XPathNodeIterator ni = nav.Select(expr);
while (ni.MoveNext()) {
Console.WriteLine(ni.Current.Value);
}

--
Oleg Tkachenko [XML MVP, MCAD]
AddThis Social Bookmark Button