Jump to content
Sign in to follow this  

Parsing opf/xml data

Recommended Posts

Hi... I am working to parse an opf file. I can pull the dc children but am having problems getting it to pull other information from the file.  Is there a way to do this?

What I am currently doing:

$package = simplexml_load_file("$url");
echo $package->metadata->children('dc', true)->creator."<br>";
echo $package->metadata->children('dc', true)->title."<br>";
echo $package->metadata->children('dc', true)->description."<br>";

Is there a way to parse the meta content by name?

File structure:

<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuid_id" version="2.0">
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
        <dc:title>The Beginning of the End</dc:title>
        <dc:creator opf:file-as="Cassidy, Amanda" opf:role="aut">Amanda Cassidy</dc:creator>
        <dc:description>Working with young children can be a very rewarding job... and extremely frustrating at the...</dc:description>
        <meta content="Preschool Teachers Anonymous" name="library:series"/>
        <meta content="1" name="library:series_index"/>


Share this post

Link to post
Share on other sites

Try this:


foreach($package->metadata->meta as $meta) {
    echo "content:{$meta['content']}  name: {$meta['name']} <br>"; 


Share this post

Link to post
Share on other sites

Join the conversation

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

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.

Sign in to follow this  

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