Groups | Blog | Home
all groups > dotnet xml > november 2003 >

dotnet xml : xpath help - single quotes


Joe Gass
11/21/2003 4:12:54 PM
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


Oleg Tkachenko
11/23/2003 12:30:51 PM
[quoted text, click to view]


[quoted text, click to view]

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
Joe Gass
11/24/2003 9:31:34 AM
Thanks for your help
I managed to get it going with this
xmldoc.SelectSingleNode("//section[title=""" & sectionTitle & """]")

\" wasn't working but "" did

Thanks


[quoted text, click to view]

AddThis Social Bookmark Button