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

  • SEARCH
  • Home
  • 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 8517211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:38:08+00:00 2026-06-11T05:38:08+00:00

I need to create an XPath expression that does the following: Returns the element

  • 0

I need to create an XPath expression that does the following:

  • Returns the element inside of ‘NodeA’ by default
  • Returns the element inside of ‘NodeB’ if it is not empty.

Here is some sample XML so that my target structure can be clearly seen (I am using MS InfoPath):

<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.10" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\9016384cab6148f6\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-07T14:19:10" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:NodeASection>
    <my:NodeA>2012-09-13</my:NodeA>
</my:NodeASection>
    <my:NodeBSection>
        <my:NodeBGroup>
            <my:NodeB>2012-09-14</my:NodeB>
        </my:NodeBGroup>
    </my:NodeBSection>
</my:myFields>

This XPath expression can be used to evaluate NodeB for the existence of text: boolean(//my:NodeB[(text())])

I have heard of the “Becker Method” but I’m not sure how that applies when both nodes exist. I’m very new to XPath and appreciate any help that can be offered.

  • 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-06-11T05:38:10+00:00Added an answer on June 11, 2026 at 5:38 am

    This XPath expression returns NodeB if it exists (and has text content) and NodeA in the other case:

    //my:NodeB[text()] | //my:NodeA[text() and not(//my:NodeB[text()])]
    

    If you want to get all sub-elements you can append /* after the selected node, like this

    //my:NodeB[text()]/* | //my:NodeA[text() and not(//my:NodeB[text()])]/*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a xpath query that will return everything listed under availabilty
I'm create a deal agregator but first i need to put xpath into database
I need create clone repository. but I do not know where can I get
I am trying to create an XPath expression for use in MS InfoPath in
I Need to create an XSL file so that I will use it to
I need to create an XML xPath parser. All parsing has to happen on
I'm reading xml document using XPath and I need to create a Document object
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need create a document word with Java. And I ask, how can I

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.