471,067 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

xpath help - single quotes

I have an xml doc
<sections>
<section>
<title>entry image</title>
</section>
<section>
<title>22'2</title>
</section>
</sections>

I want to check for duplicate nodes before I add
I'm using this vb.net code (The code is fine but the xpath isn't working
with titles with single quotes in)

Private Function nodeExists(ByVal sectionTitle As String) As Boolean
Dim xmldoc As New XmlDocument
xmldoc.Load(_xmlPath)
Dim xn As XmlNode = xmldoc.SelectSingleNode("//section[title='" &
sectionTitle & "']")
Return Not xn Is Nothing
End Function

I've also tried
sectionTitle.Replace("'", "&apos;")
But since I don't really have &apos; in the code, it isn't found
I've tried to add &apos; instead of ' when I create the node, but .net
"cleverly" changes this too &amp;apos;

Any ideas?
Thanks

Nov 12 '05 #1
2 2921
Joe Gass wrote:

Dim xn As XmlNode = xmldoc.SelectSingleNode("//section[title='" &
sectionTitle & "']")


Try " instead of '. It doesn't matter for XPath, but matters for you.
Something like
xmldoc.SelectSingleNode("//section[title=\"" & sectionTitle & "\"]")
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #2
Thanks for your help
I managed to get it going with this
xmldoc.SelectSingleNode("//section[title=""" & sectionTitle & """]")

\" wasn't working but "" did

Thanks
"Oleg Tkachenko" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ug**************@tk2msftngp13.phx.gbl...
Joe Gass wrote:

Dim xn As XmlNode = xmldoc.SelectSingleNode("//section[title='" & sectionTitle & "']")


Try " instead of '. It doesn't matter for XPath, but matters for you.
Something like
xmldoc.SelectSingleNode("//section[title=\"" & sectionTitle & "\"]")
--
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Matthew Wieder | last post: by
2 posts views Thread by Matthew Wieder | last post: by
7 posts views Thread by Ot | last post: by

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.