Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal?

Reply
Thread Tools

Problem selecting a node with XPATH if attribute value contains backslashes - how to force XPATH string to be treated as literal?

 
 
Alastair Cameron
Guest
Posts: n/a
 
      07-07-2003
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("Fa cility[@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


 
Reply With Quote
 
 
 
 
SQL Server Development Team [MSFT]
Guest
Posts: n/a
 
      07-08-2003
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>


--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
"Alastair Cameron" <(E-Mail Removed)> wrote in message
news:9mjOa.1$(E-Mail Removed)...
> 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("Fa cility[@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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nike air force one, air force 1, air force one low cut, air force one abdul_razak@indiatimes.com Digital Photography 2 12-31-2008 04:29 PM
[XSLT] Select node by attribute with value from an attribute of its self Stefan_W XML 1 11-05-2008 10:50 AM
Perl ActiveX: A VBA string passed to my control is treated as a doubel-quoted string david.f.jenkins@usa.net Perl Misc 0 10-09-2006 08:03 PM
selecting the value of the node based on the value of parameter sp XML 3 02-07-2006 02:50 PM
Save String that contains a windows file path with backslashes peter.o.mueller@gmx.de Java 1 09-05-2005 07:51 PM



Advertisments