473,395 Members | 1,987 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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

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
Nov 11 '05 #1
1 6520
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" <al**************@blueyonder.co.uk> wrote in message
news:9m***********@news-binary.blueyonder.co.uk...
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

Nov 11 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alastair Cameron | last post by:
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...
3
by: Jorn W Janneck | last post by:
hello everyone. i have the sort of question that makes me feel like i am missing the forest for the trees, so apologies if i am missing the blatantly obvious here. i am using saxon, and mostly...
4
by: elora_c | last post by:
I'm trying to write XSLT that will filter out an XML based on an attribute's value. XML looks like: <postings> <channel name="A"> <posting Connected="True" name="Posting1" /> <posting...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
2
by: Greg | last post by:
Hi. I have a rather large xml document (object) that can have one or more nodes with a certain attribute throughout (at ANY depth, not at the same level necessarily). I need to find this...
1
by: Chief | last post by:
I am unable to load an xml document that contains Chinese characters in an attribute value. I need to load the document into and XmlDocument object and am using the XmlDocument.Load(string...
1
by: orit | last post by:
I have the following xml file: <?xml version="1.0" encoding="utf-8" ?> <course id="2555" title="Developing Microsoft .NET Applications for Windows (Visual C# .NET)" length="5 days"...
2
by: Joe | last post by:
Hello All: I have an xml document that contains <Control> nodes, each of which has a "name" attribute (i.e. <Control name="myControl" />. I want to find all of the nodes that have "Recipient"...
0
by: kelvin273 | last post by:
Hi all, i'm new in this community (and in .NET programming) and i've a problem with xpathnavigator. The idea is to have an xml document with attribute editable by windows form. I write this...
5
by: jorgedelgadolopez | last post by:
Hi all, I am using the xpathnavigator evaluate function on .net (xpath 1 right?). Now I need to expand the code to do multiple contains, compare dates (such as 'before', 'between' and 'after'),...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.