473,836 Members | 1,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 "LocalServe r".

Set xmlElement = _

xmlConfigFile.d ocumentElement. selectSingleNod e("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
Nov 11 '05 #1
1 6572
Please try the following example to access the desired element.
regards
-umut alev

a.vbs
---------------
Set o = CreateObject("M SXML2.DOMDocume nt.3.0")
o.async = False
o.load("a.xml")
qs = "\\LocalSer ver"
o.setProperty "SelectionLangu age", "XPath"
WScript.echo o.selectSingleN ode("/root/e1/e2[@attr='"& qs &"']").xml

a.xml
---------------
<root>
<e1>
<e2 attr="\\RemoteS erver" >remote server</e2>
<e2 attr="\\LocalSe rver" >my local server</e2>
<e2 attr="\\Externa lServer" >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.c o.uk> wrote in message
news:9m******** ***@news-binary.blueyond er.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 "LocalServe r".

Set xmlElement = _

xmlConfigFile.d ocumentElement. selectSingleNod e("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

Nov 11 '05 #2

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

Similar topics

1
2975
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 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".
3
4969
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 xslt version 1.1 (the unofficial one). i have a template parameter, say v, which contains a sequence of nodes of the same kind, say A, which all have an attribute, say n. these attributes may have different numeric values. i have identified the...
4
2032
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 Connected="False" name="Posting2" /> </channel> <channel name="B"> <channel name="C">
5
3467
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 clear. But how should parser react for such situation: I have CORDSYS element with string attribute which consists of value with many &quot; entities:
2
10705
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 attribute and remove the containing node (and child nodes) if it has a certain value. I'm able to find the attributes using an XmlTextReader. Once found, can someone help me get the XPath at that point? I would then use this to remove the node from...
1
3556
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 filename) method. I get an error that says the document contains invalid characters. The document loads fine with Chinese characters in a node value, but not in an attribute value. I have tried setting the encoding to UTF-8 and UTF-16, but neither solve...
1
2942
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" source="http://www.microsoft.com/learning/syllabi/en-us/2555Afinal.mspx"> <module id="1" title="Introducing Windows Forms" location="D:\Disk-C\Documents and Settings\orit_itzhar.ATRICA\My Documents\XML\csharp"> <lesson id="1.1"> <subject>Creating a...
2
939
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" anywhere in the name attribute's value. So, if I have the following: <Controls> <Control name="PrimaryRecipient" /> <Control name="RecipientCC1" />
0
1796
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 code, where xPath is, of course, the correct path of the selected node, and NodeEntity is a class that encapsulate the new attribute value. The method extract value from NodeEntity and update attribute value of the current node. But i don't find the...
5
50589
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'), and so on. This is the thought: //person
0
9672
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10854
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10601
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9388
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5652
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5829
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.