Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH str

  • Thread starter Alastair Cameron
  • Start date
A

Alastair Cameron

VB6, MSXML 3.2 installed:

Q1.

I am having a problem selecting nodes with XPATH expressions when an
attribute values contain backslashes (\\) in as part of its value:

For example the following statement fails to find a node (even though one
exists in the XML) if the value of the LDAPServerURL attribute is
\\LocalServer but works if the value is "LocalServer".

Set xmlElement = _

xmlConfigFile.documentElement.selectSingleNode("Facility[@LDAPServerURL='" &
<SomeValue> & "']")

I assumed that anything inside the '' was treated as a literal, but XPATH
looks like it is using the backslashes in a XPATH context.

What do I need to do to get anything insde the '<SomeValue>' treated as a
string literal...?

Q2.

Second question: if my attribute values contains embedded single quote (')
or double quotes ("") how do I handle both circumstances when building XPATH
expressions to retrieve them?

Thanks.

Alastair
 
S

SQL Server Development Team [MSFT]

Please try the following example to access the desired element.
regards
-umut alev

a.vbs
---------------
Set o = CreateObject("MSXML2.DOMDocument.3.0")
o.async = False
o.load("a.xml")
qs = "\\LocalServer"
o.setProperty "SelectionLanguage", "XPath"
WScript.echo o.selectSingleNode("/root/e1/e2[@attr='"& qs &"']").xml

a.xml
---------------
<root>
<e1>
<e2 attr="\\RemoteServer" >remote server</e2>
<e2 attr="\\LocalServer" >my local server</e2>
<e2 attr="\\ExternalServer" >external server</e2>
</e1>
</root>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top