Jump to content

xpath elements and attributes


inogen

Recommended Posts

Hi all,

 

I'm sure I'm making this far more difficult than I need to...

 

I've got an xml document...

 

<library id="1">

<lname>Lib1</name>

<book id="1">

<title>book 1</title>

<author>Author 1</author>

</book>

<book id="2">

<title>book 2</title>

<author>Author 2</author>

</book>

</library>

 

I can access the nested elements using xpath like :

 

$result = $xml->xpath('//book');

 

    foreach($result as $books) {

        echo $books->title;

    }

 

How would I do this for the attributes? If I specify I want the attributes in the xpath query I can't get at the elements...

 

I'm trying to turn this xml file into a simple relational database... A library table and a book table.

 

So I need the library id (attribute) and the name(nested element) for one insert query - and the book id, title, author and the library id for the other.

 

 

Anyone got any idea?

 

Cheers

 

John

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/220910-xpath-elements-and-attributes/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.