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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:08:16+00:00 2026-05-21T09:08:16+00:00

I have an xml how can I get the node in levelone that has

  • 0

I have an xml how can I get the node in levelone that has an attribute called myatt whose value is a and then access it’s myval.
I tried referencing other posts to make it work but it doesn’t seem to work what’s wrong with my xpath

$this->myXmlObj->xpath("//levelone[myfield[attributes/myatt='a]]]"));

<myxml>
  <levelone>
      <myfield myatt="a" myval="aa" />
      <myfield myatt="b" myval="bb" />

  </levelone>  
  <leveltwo>
      <myfield myatt="c" myval="dd" />
      <myfield myatt="c" myval="dd" />
  </leveltwo>
</myxml>

edit 1

array
  0 => 
    object(SimpleXMLElement)[41]
      public '@attributes' => 
        array
          'myval' => string 'a' (length=40)

edit 2

    $myVar = $this->myXmlObj->xpath("//levelone/myfield[@myatt='a']");
    $myOutput = ((string)$myVar[0]->attributes()->myVal;
  • 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-21T09:08:17+00:00Added an answer on May 21, 2026 at 9:08 am

    Attributes in XPATH are referenced with @attr syntax. So, you could retrieve aa with the following xpath

    //levelone/myfield[@myatt=’a’]/@myval

    Which means, grab all myfield elements that have attribute myatt equal to 'a'. Then, from those, select the value of their myval attributes. Note that this could be multiple results.

    A handy place to test XPATH expressions is at http://chris.photobooks.com/xml/default.htm.

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

Sidebar

Related Questions

I have very simple xml <root> <node>some value</node> </root> How can I get the
How can I get each node's attribute via xpath? For instance, book.xml, <?xml version=1.0
So I have this script that reads the xml, modifies the selected node value
I need to have following attribute value in my XML node: CommandLine=copy $(TargetPath) ..\..\&#x0D;&#x0A;echo
So, i have some question about xml Documents in Java. Can i get all
I have the following XML Document (that can be redesigned if necessary) that stores
I have a .xml file in my App_Data folder, I can access it fine
If I have an XML file that includes <param name=foo value=5000 >foo is a
I have some XML that is a single level with an attribute that I
I have an object that I can get a String from during debugging. That

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.