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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:35+00:00 2026-05-29T08:05:35+00:00

I am working on an interface with the amazon product advertising API. I have

  • 0

I am working on an interface with the amazon product advertising API.

I have XML that includes a section similar to this:

<BrowseNodes>
  <BrowseNode>
     <Name>Category</Name>
     <BrowseNodeId>123456</BrowseNodeId>
     <Ancestors>
       <BrowseNode>
         <Name>Whatever</Name>
        <BrowseNodeId>987654</BrowseNodeId>
       <BrosweNode>
     </Ancestors>
  </BroseNode>
  <BroseNode>
  ...
  </BrowseNode>
</BrowseNodes>

I’ll have to double check my XML. there might be one more level of <BrowseNode> </BrowseNode> outside of the first <BrowseNode> I posted above.

I need to find the <BrowseNode> <Name> that is inside the Ancestors element where the <Ancestors> element is a sibling of the <Name>Category</Name>

I’m just getting started with xpath, and that’s over my head.

I have been coding it like this:

//$XML fromapi
$parsed=simplexml_load_string($XML);

//narrow it down
$s = '/ItemSearchResponse/Items/Item';
$items = $parsed->xpath($s);

//Get only the top level BrowseNodes for this item.
foreach($items as $item)
  {
    // this narrows it down close to what I posted above.
    $s = 'BrowseNodes/BrowseNode';
    $top_browsenode_search=$item->xpath($s);

      //there may be a simpler way, but I think it is working for me:
      foreach ($top_browsenode_search as $top_browsenode)
        {
          $temp_array=array();//must be emptied each time.
          $s = 'Name';
          $temp_array['name']=$top_browsenode->xpath($s);
          $s = 'BrowseNodeId';
          $temp_array['id']=$top_browsenode->xpath($s);

      $browsenodes[]=$temp_array;
        }
    $top_browsenodes[]=$browsenodes;
    unset ($browsenodes);        
  }    

Is anyone able to help with that xpath syntax? If not directly, could you point me to any novice friendly documentation you know of? I downloaded a great book on the subject, I’ve learned a lot from it, but It’s a little over my head.

below is not part of the question, but rather evidence that one of the answers was correct. See the comments for details.
Expected result: “Whatever” Given Result: “Whatever”

<?xml version="1.0" ?>
<root>
<BrowseNodes>
  <BrowseNode>
     <Name>Category</Name>
     <BrowseNodeId>123456</BrowseNodeId>
     <Ancestors>
       <BrowseNode>
         <Name>Whatever</Name>
         <BrowseNodeId>987654</BrowseNodeId>
       </BrowseNode>
     </Ancestors>
  </BrowseNode>
  <BrowseNode>
     <Name>SomethingElse</Name>
     <BrowseNodeId>951753</BrowseNodeId>
  </BrowseNode>
</BrowseNodes>
</root>
BrowseNodes/BrowseNode/Name
Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => Category
        )

    [1] => SimpleXMLElement Object
        (
            [0] => SomethingElse
        )

)

BrowseNodes/BrowseNode[Name="Category"]/Ancestors/BrowseNode/Name 
Array
(
    [0] => SimpleXMLElement Object
        (
            [0] => Whatever
        )

)

Thanks!

  • 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-29T08:05:36+00:00Added an answer on May 29, 2026 at 8:05 am

    If you want to get just the node:

    BrowserNodes/BrowserNode[Name=_______]/Ancestors/BrowserNode/Name
    

    If you want to get the node’s text:

    BrowserNodes/BrowserNode[Name=_______]/Ancestors/BrowserNode/Name/text()
    

    In both examples, replace _ with the name for which you are searching.

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

Sidebar

Related Questions

I'm writing a Scala client to interface with Amazon's RESTful Product API . To
I'm working with an interface that takes type Object as its input. This is
I am working on an interface that requires that the user can click on
I'm working on an interface with a 3rd party app that basically needs to
I'm working on a webservice + AJAX interface, and I'm worried about authentication. This
I'm working on an application that loads untrusted assemblies via an interface. Each of
I'm working on a module that requires a strictly decoupled interface. Specifically, after instantiating
I am working on a interface in java swing.we have four system connected with
I've got an XIB window that I'm working with in Interface Builder. It has
I have a working GPIB interface and Linux-GPIB package installed and working. I only

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.