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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.