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

Discussion in 'XML' started by Alastair Cameron, Jul 7, 2003.

  1. 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
     
    Alastair Cameron, Jul 7, 2003
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:9mjOa.1$...
    > 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], Jul 8, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    14,849
    Roedy Green
    Sep 5, 2005
  2. Tjerk Wolterink

    XPath: Selecting namspace node

    Tjerk Wolterink, Sep 18, 2004, in forum: XML
    Replies:
    1
    Views:
    434
    Tjerk Wolterink
    Sep 18, 2004
  3. sp
    Replies:
    3
    Views:
    467
    Joseph Kesselman
    Feb 7, 2006
  4. Replies:
    1
    Views:
    576
    Martin Honnen
    May 8, 2007
  5. Stefan_W
    Replies:
    1
    Views:
    8,291
    Stefan_W
    Nov 5, 2008
Loading...

Share This Page