Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / July 2003

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alastair Cameron - 07 Jul 2003 19:55 GMT
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
SQL Server Development Team [MSFT] - 08 Jul 2003 20:24 GMT
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>

Signature

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.

> VB6, MSXML 3.2 installed:
>
[quoted text clipped - 27 lines]
>
> Alastair

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.