Results 1 to 4 of 4

Thread: XPath Invalid Token in Query String

  1. #1

    Thread Starter
    Lively Member jberman's Avatar
    Join Date
    Nov 2004
    Location
    Hollywood, FL
    Posts
    103

    XPath Invalid Token in Query String

    Not sure if this is a question for the XML forum or the VB .Net forum but here goes. I am trying to use the VB .Net Xml.XmlNode object's SelectSingleNode method to grab a node I need. The XML string I am searching looks something like this.

    <DataRow rowNumber="251">
    <RowData rowType="item" value="MD:Z-Bar 4' Length" />
    <ColData colID="1" value="Z-Bar 4' Length" />
    <ColData colID="2" value="Z-Bar 4' Length" />
    <ColData colID="4" value="10" />
    <ColData colID="5" value="75" />
    <ColData colID="6" value="0" />
    <ColData colID="7" value="75" />
    <ColData colID="8" value="false" />
    <ColData colID="9" value="0" />
    <ColData colID="11" value="0" />
    </DataRow>

    I try to grab the node from a larger list of DataRow node via the following VB .Net Code

    VB Code:
    1. MyNode.SelectSingleNode( MyValidPathString & "DataRow[RowData [value=('MD:Z-Bar 4' Length')]]/ColData [@colID='5']").Attributes("value").InnerXml

    At this line of code an System.Xml.XPath.XPathException is thrown with the message:

    MyValidPathString & "DataRow[RowData [value=('MD:Z-Bar 4' Length')]]/ColData [@colID='5']' has an invalid token.

    I know the cause of this is the apostrophe in my search string, MD:Z-Bar 4' Length, but I do not know how to get the node I need any other way. I tried:

    'MD:Z-Bar 4" Length'
    'MD:Z-Bar 4&apos; Length'
    "MD:Z-Bar 4' Length"
    'MD:Z-Bar 4'' Length'
    etc....

    Can anyone help me out?

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XPath Invalid Token in Query String

    Try \'
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Lively Member jberman's Avatar
    Join Date
    Nov 2004
    Location
    Hollywood, FL
    Posts
    103

    Re: XPath Invalid Token in Query String

    Same error

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    Re: XPath Invalid Token in Query String

    Then try this:
    "DataRow[RowData/@value='MD:Z-Bar 4\' Length']/ColData[@colID='5']"
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width