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 101161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:43:05+00:00 2026-05-11T00:43:05+00:00

I need to locate the node within an xml file by its value using

  • 0

I need to locate the node within an xml file by its value using XPath. The problem araises when the node to find contains value with whitespaces inside. F.e.:

<Root>   <Child>value</Child>   <Child>value with spaces</Child> </Root> 

I can not construct the XPath locating the second Child node.

Simple XPath /Root/Child perfectly works for both children, but /Root[Child=value with spaces] returns an empty collection.

I have already tried masking spaces with %20, & #20;, & nbsp; and using quotes and double quotes.

Still no luck.

Does anybody have an idea?

  • 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. 2026-05-11T00:43:06+00:00Added an answer on May 11, 2026 at 12:43 am

    Depending on your exact situation, there are different XPath expressions that will select the node, whose value contains some whitespace.

    First, let us recall that any one of these characters is ‘whitespace’:

        &#x09; — the Tab

        &#xA; — newline

        &#xD; — carriage return

        ' ' or &#x20; — the space

    If you know the exact value of the node, say it is ‘Hello World‘ with a space, then a most direct XPath expression:

         /top/aChild[. = 'Hello World']

    will select this node.

    The difficulties with specifying a value that contains whitespace, however, come from the fact that we see all whitespace characters just as … well, whitespace and don’t know if a it is a group of spaces or a single tab.

    In XPath 2.0 one may use regular expressions and they provide a simple and convenient solution. Thus we can use an XPath 2.0 expression as the one below:

        /*/aChild[matches(., 'Hello\sWorld')]

    to select any child of the top node, whose value is the string ‘Hello’ followed by whitespace followed by the string ‘World’. Note the use of the matches() function and of the ‘\s‘ pattern that matches whitespace.

    In XPath 1.0 a convenient test if a given string contains any whitespace characters is:

    not(string-length(.)= stringlength(translate(., ' &#9;&#xA;&#xD;','')))

    Here we use the translate() function to eliminate any of the four whitespace characters, and compare the length of the resulting string to that of the original string.

    So, if in a text editor a node’s value is displayed as

    ‘Hello    World’,

    we can safely select this node with the XPath expression:

    /*/aChild[translate(., ' &#9;&#xA;&#xD;','') = 'HelloWorld']

    In many cases we can also use the XPath function normalize-space(), which from its string argument produces another string in which the groups of leading and trailing whitespace is cut, and every whitespace within the string is replaced by a single space.

    In the above case, we will simply use the following XPath expression:

    /*/aChild[normalize-space() = 'Hello World']

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

Sidebar

Ask A Question

Stats

  • Questions 76k
  • Answers 76k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer int exampleID = 5; //now to write a query var… May 11, 2026 at 3:08 pm
  • added an answer Use POSIX::tzset. use POSIX qw(tzset); my $was = localtime; print… May 11, 2026 at 3:07 pm
  • added an answer SELECT TOP 1 employee.name, employee.salary from ( SELECT TOP N… May 11, 2026 at 3:07 pm

Related Questions

I need to locate the index position of a record in a large database
I need to parse pretty big XML in PHP (like 300 MB). How can
I have written a Windows service that allows me to remotely run and stop
Greeting Everyone I'm trying to compile and run a multi-language code in C, C++

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.