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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:42:24+00:00 2026-05-16T00:42:24+00:00

I’m trying to wrap my head around PHP and XML. I’m trying to do

  • 0

I’m trying to wrap my head around PHP and XML.

I’m trying to do something:

There is an XML document that I’m retrieving via cURL (also tried various PHP XML library parameters such as XMLReader::open($url) etc. The method of retrieval doesn’t matter; I can and have got this part working.

The problem is parsing the XML on the retrieved page.

Here is an example of the XML:

http://z3950.loc.gov:7090/voyager?version=1.1&operation=searchRetrieve&query=9780471615156&maximumRecords=1&recordPacking=xml&recordSchema=marcxml

What I need to get from that page is the call number;

<datafield tag="060" ind1=" " ind2=" ">
  <subfield code="a">WM 173.6 R823m</subfield>
</datafield>

author;

<datafield tag="100" ind1="1" ind2=" ">
  <subfield code="a">Ross, Colin A.</subfield>
</datafield>

and title information;

<datafield tag="245" ind1="1" ind2="0">
  <subfield code="a">Multiple personality disorder :</subfield>
  <subfield code="b">diagnosis, clinical features, and treatment /</subfield>
  <subfield code="c">Colin A. Ross.</subfield>
</datafield>

seems simple enough. However, for the life of me I can not seem to get any of the inbuilt PHP functions for working with XML to work (because I’m doing it wrong).

Here is an example I’ve tried:

//xml file retrieved via curl and saved to folder
$file="9780471615156.xml";

$xml = simplexml_load_file($file);

echo $xml->getName();//returns searchRetrieveResponse

foreach($xml->searchRetrieveResponse[0]->attributes() as $a => $b){
  echo $a,'="',$b,"\"</br>";//nothing
 }

foreach ($xml->searchRetrieveResponse[0]->children() as $child){
  echo "Child node: " . $child . "<br />";//nothing
}

it returns the name of the first node, but I can’t get it to go any deeper.

NB: I’m running PHP 5+

  • 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-16T00:42:25+00:00Added an answer on May 16, 2026 at 12:42 am

    as far as I tried the simpleXML can not read this XML. Try the example below, it will list an array which you can easily loop trought and find what you need simply by comparing keys/values you’re looking for.

    // load XML into string here
    // $string = ????;
    $xml_parser = xml_parser_create();
    xml_parse_into_struct($xml_parser, $string, $object, $index);
    
    echo '<pre>';
    print_r($object);
    // print_r($index);
    echo '</pre>';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.