0

I have some XPath code that's working great 99% of the time. But now I have an XML document that contains unescaped characters in it. In this case the string I'm looking for is something like "Maury's bad string".

So how do I construct an XPath query to find this string? I tried escaping:

../a:Data[a:Name='" & NewT.Name.Replace("'", "'") & "'"

But that fails to match the text. So then I tried:

../a:Data[a:Name='" & NewT.Name.Replace("'", "''") & "'"

But that tells me there's an invalid token in the search string.

Anyone know the trick here?

Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98

1 Answers1

0

This is NOT a complete solution, as it only works if the strings contain single or double quotes, but not both:

Dim S As String
If Name.Contains("'") Then
    S = ../a:Data[a:Name=""" & Name & """
Else
    S = ../a:Data[a:Name='" & Name & "'"
End If
Maury Markowitz
  • 9,082
  • 11
  • 46
  • 98