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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:07:04+00:00 2026-05-24T02:07:04+00:00

I can read the input of a xml file in an array simply like

  • 0

I can read the input of a xml file in an array simply like this :

  <?php
  $doc = new DOMDocument();
  $doc->load( 'books.xml' );

  $books = $doc->getElementsByTagName( "book" );
  foreach( $books as $book )
  {
  $authors = $book->getElementsByTagName( "author" );
  $author = $authors->item(0)->nodeValue;

  $publishers = $book->getElementsByTagName( "publisher" );
  $publisher = $publishers->item(0)->nodeValue;

  $titles = $book->getElementsByTagName( "title" );
  $title = $titles->item(0)->nodeValue;

  echo "$title - $author - $publisher\n";
  }
  ?>

And lets the xml file to an example something like this :

  <books>
  <book>
  <author>Jack Herrington</author>
  <title>PHP Hacks</title>
  <publisher>O'Reilly</publisher>
  </book>
  <book>
  <author>Jack Herrington</author>
  <title>Podcasting Hacks</title>
  <publisher>O'Reilly</publisher>
  </book>
  </books>

But If i want to match at a certain level lets say I want to FIND the number of matching elements like in mySql has LIKE or ==.

And return the result to an array or something

  • 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-24T02:07:04+00:00Added an answer on May 24, 2026 at 2:07 am

    XPATH is what you are looking for I think.

    For instance, all books published by O’Reilly:

    <?php
    $doc = new DOMDocument();
    $doc->load( '/tmp/books.xml' );
    $x = new DOMXPath($doc);
    foreach($x->query('//book[publisher="O\'Reilly"]') as $book){
        echo $book->ownerDocument->saveXML($book);
    }
    //If you only want the count:
    echo $x->evaluate('count(//book[publisher="O\'Reilly"])');
    

    XPath is my opinion more easy to learn then SQL, but by no means a ‘look at it for a couple of minutes and you’re done’, you’ll really have to learn it if your needs are more complex then the bare basics.

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

Sidebar

Related Questions

I would like to know how can i read a value of input text
I can read settings like this, for example: final String mytest = System.getString(this.getContentResolver(), System.AIRPLANE_MODE_ON);
I am receving an XML file as an input, whose size can vary from
So a form like this: <form action=/appapi/checkout/ method=post mimetype=text/xml enctype=text/xml name=form1> <input type=file name=xmlfile>
You can read this question where I ask about the best architecture for a
How you can read a file (text or binary) from a batch file? There
For what I can read, it is used to dispatch a new thread in
I am trying to read an XML file into a data set using dataset.ReadXml(fileName,
I'm getting a NullReferenceException upon trying to read an attribute of an xml-file -
I have a text read from a XML file stored in UTF8 encoding. C#

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.