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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:34:36+00:00 2026-05-31T15:34:36+00:00

Hoi, for example, i have a xml file : <bookstore> <book category=COOKING> <title lang=en>Everyday

  • 0

Hoi,

for example, i have a xml file :

<bookstore>

<book category="COOKING">
  <title lang="en">Everyday Italian</title>
  <author>Giada De Laurentiis</author>
  <year>2005</year>
  <price>30.00</price>
</book>

<book category="WEB">
  <title lang="en">XQuery Kick Start</title>
  <author>James McGovern</author>
  <author>Per Bothner</author>
  <author>Kurt Cagle</author>
  <author>James Linn</author>
  <author>Vaidyanathan Nagarajan</author>
  <year>2003</year>
  <price>49.99</price>
</book>

</bookstore>

And I want all the titles and prices

I could write this code

<php
$res = $xpath->query('/bookstore/book/title');
foreach ($res as $item) {
  echo "{$item->nodeValue}";
}  
$res = $xpath->query('/bookstore/book/price');
foreach ($res as $item) {
  echo "{$item->nodeValue}";
}  
?>

But this looks very ugly,
Is there another possibility so that I can combine those 2 blocks of code?

something like this?

<php
$res = $xpath->query('/bookstore/book');
foreach ($res as $item) {
  echo "{$item->title} <br/> {$item->price}";
}  
?>

Kind regards

  • 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-31T15:34:37+00:00Added an answer on May 31, 2026 at 3:34 pm

    You could adjust your XPATH with concatenate to read ‘/bookstore/book/title | /bookstore/book/price’
    This would give you a node list as such:

    <title lang="en">Everyday Italian</title>
    <price>30.00</price>
    <title lang="en">XQuery Kick Start</title>
    <price>49.99</price>
    ...
    ...
    

    Then just pull values 1 and 2 in each foreach loop cycle for what you like.

    Hope this helps!

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

Sidebar

Related Questions

Hoi! I have a form I wish to submit, but I need to add
Say I have html similar to the following <ul> <li> hi </li> <li> hoi
Hoi, I have a dynamic library loader, which is written in C++ but provides
Hoi. I am working on an experiment allowing users to use 1% of my
I have a red box called mc1_mc and every time when you drag on
I'm working on a translation function that should work like this: _('{en:}hello{nl:}hoi') But I'm
Hoi. I love Eclipse. But i hate that huge square annotation on the left,
I have the following data. df = data.frame(email_one=c(one@gkn.com,two@wern.com,three@fu.cin, four@huo.com,five@hoi.com), email_two=c(ten@hoinse.com, four@huo.com,two@wern.com,five@hoi.com,six@ihoio.com)) I'm wondering if
Hi every one I have a parsing RSS question. Current, I am able to
I have a MVC3 action method with 3 parameters like this: var url =

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.