472,789 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,789 software developers and data experts.

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() ?

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;
May 24 '06 #1
4 4380
Daniel wrote:
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;


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
May 24 '06 #2
Daniel wrote:
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;


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
May 24 '06 #3
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]" <so**@body.com> wrote in message
news:Of**************@TK2MSFTNGP03.phx.gbl...
Daniel wrote:
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;


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

May 25 '06 #4
Daniel wrote:
EXSLT.NET has nothing to support regular expressions inside of xpath for
System.Xml.XmlNode xpath methods such as SelectNodes or SelectSingleNode


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
May 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Bailo | last post by:
I wrote a webservice to output a report file. The fields of the report are formatted based on information in an in-memory XmlDocument. As each row of a SqlDataReader are looped through, a...
4
by: Andreas Håkansson | last post by:
I have a price of XML that looks like this <Root> <SomeNode> ..... </SomeNode> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> ... </Signature> </Root>
7
by: Ot | last post by:
I posted this to the wrong group. It went to m.p.dotnet.languages.vb. Ooops. -------------------------------------------------------------------- I have this tiny problem. I have learned...
3
by: Shawn | last post by:
Hi. I have an XML file that looks like this: <?xml version="1.0" encoding="utf-16"?> <Transfer> <Config xmlns="http://www.mysite.com/Transfer/"> <site>NY</site> </Config> </Transfer> I'm...
2
by: J Mon | last post by:
I have a XML document with elements like <offer> <field name="name"><!]></field> <field name="merchant_id"><!]></field> ..... </offer> I know not the best XML! Now I am selecting different...
6
by: Chua Wen Ching | last post by:
Hi there, I had this xml file with me (not yet consider implementing xml namespaces yet). <?xml version='1.0'?> <Object> <Windows> <EID>1</EID> <EDesc>Error 1</EDesc> </Windows>
5
by: Chua Wen Ching | last post by:
Hi, I read from this tutorial at codeproject Question A: http://www.codeproject.com/csharp/GsXPathTutorial.asp regarding xpath.. but i try to apply in my situation, and can't get it...
2
by: probashi | last post by:
Hi, >From the sample xml, I am trying to select a book and then select the author of the select book. In the example code first SelectSingleNode selects a book. Second SelectSingleNode on the...
1
by: Daniel | last post by:
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>";...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.