Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Nov 05, 2006 10:10 AM by olegt
Member
5 Points
1 Post
Nov 03, 2006 12:43 AM|LINK
If I want to select book has name ABCD , I can writee elem.SelectSingleNode( @""book[ @Name = ""ABCD""]"");
BUT IF I want to select book has name A'B'C"D" how to select ?
Please help me ,thank you very very much.
the XPATH standard says:
http://www.w3.org/TR/xpath
xpath
156 Points
40 Posts
Nov 03, 2006 09:31 AM|LINK
need to use the translate function
try reading this first
http://www.biglist.com/lists/xsl-list/archives/200004/msg00280.html
Participant
1530 Points
297 Posts
MVP
Nov 05, 2006 10:10 AM|LINK
XPath is designed to be embedded language. It delegates such issues to the host language - be it XSLT or C#. Usual way to solve such convolute problems is to have key value in a variable.
In XSLT it would look like
<xsl:variable name="title">A'B'C"D"</xsl:variable>
<xsl:value-of select="//book[title=$title]"/>
In .NET there is support for variables in XPath selections, but it's quite convolute. Much easier is to use handy Mvp.Xml XPathCache class:
XmlNode book = XPathCache.SelectSingleNode("//book[title=$title]", doc, new XPathVariable("title", "A'B'C\"D\"")); Console.WriteLine(book.OuterXml);
You can get Mvp.Xml library at http://www.codeplex.com/Wiki/View.aspx?ProjectName=MVPXML
waldenchen
Member
5 Points
1 Post
How to escape xpath in SelectSingleNode?
Nov 03, 2006 12:43 AM|LINK
If I want to select book has name ABCD , I can writee elem.SelectSingleNode( @""book[ @Name = ""ABCD""]"");
BUT IF I want to select book has name A'B'C"D" how to select ?
Please help me ,thank you very very much.
the XPATH standard says:
http://www.w3.org/TR/xpath
xpath
stevefdotnet
Member
156 Points
40 Posts
Re: How to escape xpath in SelectSingleNode?
Nov 03, 2006 09:31 AM|LINK
need to use the translate function
try reading this first
http://www.biglist.com/lists/xsl-list/archives/200004/msg00280.html
olegt
Participant
1530 Points
297 Posts
MVP
Re: How to escape xpath in SelectSingleNode?
Nov 05, 2006 10:10 AM|LINK
XPath is designed to be embedded language. It delegates such issues to the host language - be it XSLT or C#. Usual way to solve such convolute problems is to have key value in a variable.
In XSLT it would look like
<xsl:variable name="title">A'B'C"D"</xsl:variable>
<xsl:value-of select="//book[title=$title]"/>
In .NET there is support for variables in XPath selections, but it's quite convolute. Much easier is to use handy Mvp.Xml XPathCache class:
XmlNode book = XPathCache.SelectSingleNode("//book[title=$title]",
doc, new XPathVariable("title", "A'B'C\"D\""));
Console.WriteLine(book.OuterXml);
You can get Mvp.Xml library at http://www.codeplex.com/Wiki/View.aspx?ProjectName=MVPXML
XmlLab.Net | http://blog.tkachenko.com