Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3273412
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:55:45+00:00 2026-05-17T18:55:45+00:00

I trying to parse a string in an XML node by using an XPath

  • 0

I trying to parse a string in an XML node by using an XPath query which requires that I strip out a substring and read the remaining value. The substring may have a dynamic amount of whitespace before and after it before I can get to the value, so it would be helpful to have some sort of a indexOf function to use in the XPath. I’m trying to use substring-after, but there is a good chance the XPath is 1.0, which according to this post might make this more difficult to accomplish. The following is an example of the XML I am trying to parse:

<root>
   <myField>     StringToParse        7</myField>
</root>

I’m trying to get at the value 7 in the string, which would seem possible with some combination of substring-after and normalize-space. I’m not entirely sure I’m using it correctly because no matter which way I try to use it, the result is either a null value or the entire string, with the substring not removed.

The way I am able to return the entire value (the lesser of two evils) is:

/myField[substring-after(.,'StringToParse')]

which I would hope would return ‘ 7’ Could anyone let me know I’m doing wrong with the syntax, or if there is an alternate method I should be using to accomplish what I want?

Thanks,

Mike

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:55:45+00:00Added an answer on May 17, 2026 at 6:55 pm

    The way I am able to return the entire
    value (the lesser of two evils) is:
    /myField[substring-after(.,'StringToParse')],
    which I would hope would return ‘ 7’
    Could anyone let me know I’m doing
    wrong

    You are close, but there are at least two problems with the expression:

    /myField[substring-after(.,'StringToParse')]

    1. myField is not the top element in the document and this expression requests that the top element be selected and that this element’s name is myField. If evaluated against the provided XML document, no node would be selected, because the top element in the provided XML document is named root.

    2. The function call to substring-after() is inside a predicate. This means that the top node named myField is to be selected depending on the value of the call to substring-after(), converted to boolean. This is clearly what you want — you dont want a node — you want a string!

    Solution:

    substring-after(/*/myField, 'StringToParse')
    

    evaluates to (without the quotes):

    "        7"
    

    A better solution may be:

    normalize-space(substring-after(/*/myField, 'StringToParse'))
    

    this evaluates to just:

    "7"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a date/time string using DateTime.ParseExact . It works everywhere, except
I'm trying to parse objects to XML in Delphi, so I read about calling
I'm trying to parse a simple string in C++. I know the string contains
I'm trying to parse an international datetime string similar to: 24-okt-08 21:09:06 CEST So
I'm trying to parse an INI file using C++. Any tips on what is
I have been trying to parse Java exceptions that appear in a log for
I am trying to parse JSON in an Adobe Flex app, using http://www.mikechambers.com/blog/2006/03/28/tutorial-using-json-with-flex-2-and-actionscript-3/'>This Tutorial
I'm trying to parse an array of JSON objects into an array of strings
I'm trying to parse a grammar in ocamlyacc (pretty much the same as regular
I'm trying to parse a html page and extract 2 values from a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.