Connecting Tech Pros Worldwide Forums | Help | Site Map

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

Daniel
Guest
 
Posts: n/a
#1: May 24 '06
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;





Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#2: May 24 '06

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


Daniel wrote:[color=blue]
> 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;[/color]

Yes, when using EXSLT.NET. See
http://msdn.microsoft.com/xml/defaul...ctexslt_topic4

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#3: May 24 '06

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


Daniel wrote:[color=blue]
> 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;[/color]

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

--
Oleg Tkachenko [XML MVP, MCAD]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Daniel
Guest
 
Posts: n/a
#4: May 25 '06

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


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/defaul...ctexslt_topic4


"Oleg Tkachenko [MVP]" <some@body.com> wrote in message
news:OfWBlC0fGHA.1856@TK2MSFTNGP03.phx.gbl...[color=blue]
> Daniel wrote:[color=green]
>> 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;[/color]
>
> Yes, when using EXSLT.NET. See
> http://msdn.microsoft.com/xml/defaul...ctexslt_topic4
>
> --
> Oleg Tkachenko [XML MVP, MCAD]
> http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com[/color]


Oleg Tkachenko [MVP]
Guest
 
Posts: n/a
#5: May 25 '06

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


Daniel wrote:[color=blue]
> EXSLT.NET has nothing to support regular expressions inside of xpath for
> System.Xml.XmlNode xpath methods such as SelectNodes or SelectSingleNode[/color]

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]
http://www.XmlLab.Net | http://www.XLinq.Net | http://blog.tkachenko.com
Closed Thread