0

Possible Duplicate:
PHP - How to parse this xml?
Parse xml with php - storing parts into array (close to deletion or already deleted)

If I had the following XML file and I wanted to save the values in the tags name and number into an array called department, how would I be able to do it using PHP?

  <?xml version="1.0"?>
  <data>
    <record id="1">
      <department>
        <name>ACME</name>
        <number>5</number>
      </department>
      <floor>
        <name>ACME Floor</name>
        <number>5</number>
      </floor>
    </record>
  </data>
1
  • You could look at SimpleXML to do this. Commented Feb 10, 2012 at 22:54

1 Answer 1

2

You should use

DOMDocument::loadXML

<?php
    $doc = new DOMDocument();
    $doc->load('book.xml');
    $books = $dom->getElementsByTagName('book');
    foreach ($books as $book) {
        echo $book->nodeValue, PHP_EOL;
    }

?>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.