Domanda

Mi piacerebbe analizzare il contenuto di un .opf-file (Questo è un file che contiene i meta dati dei file ebook-file - .epubs nel mio caso) usando Simplexml .

Tuttavia, non riesco a ottenere oggetti come <dc:title> o <dc:creator opf:file-as="xxx" opf:role="xxx">.

per il file hitchhiker.opf (vedi sotto) Ho provato quanto segue:

<?php
$opf = simplexml_load_file("hitchhiker.opf");
$namespaces = $opf->getNameSpaces(true);
$dc = $opf->children($namespaces['dc']); 
echo $dc->title;
echo "\r\n";
echo $dc->creator;
?>
.

Ma ciò non produce un'uscita.

Se questo può essere fatto più facilmente con altri strumenti rispetto a SimpleXML, anche questo sarebbe bene.

hitchhiker.opf:

<?xml version='1.0' encoding='utf-8'?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uuid_id">
    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf">
        <dc:identifier opf:scheme="calibre" id="calibre_id">8</dc:identifier>
        <dc:identifier opf:scheme="uuid" id="uuid_id">36515eb7-1a25-4469-b55e-0042d45ca508</dc:identifier>
        <dc:title>The Hitchhiker's Guide to the Galaxy</dc:title>
        <dc:creator opf:file-as="Adams, Douglas" opf:role="aut">Douglas Adams</dc:creator>
        <dc:contributor opf:file-as="calibre" opf:role="bkp">calibre (0.7.43) [http://calibre-ebook.com]</dc:contributor>
        <dc:date>1997-06-22T07:00:00+00:00</dc:date>
        <dc:description>SUMMARY:
Don't panic! You're not timetripping! It's the tenth anniversary of the publication of Douglas Adams's zany, best-selling novel, and to celebrate Harmony is reissuing a special edition of this cult classic!By now the story is legendary. Arthur Dent, mild-mannered, out-to-lunch earth-ling, is plucked from his planet by his friend Ford Prefect just seconds before it was demolished to make way for a hyper-space bypass. Ford, posing as an out-of-work actor, is a researcher for the revised edition of The Hitchhiker's Guide to the Galaxy. Together the gruesome twosome begin their now-famous inter-galactic journey through time, space and best-sellerdom.For Hitchhiker fanatics (you know who you are!) who've read the books, seen the television program, and listened to the radio show, as well as newcomers to Douglas Adams's unique universe -- remember -- don't panic, don't forget to bring a towel, and don't forget to celebrate The Hitchhiker's Guide to the Galaxy's tenth anniversary by wearing your bathrobe.From the Hardcover edition.</dc:description>
        <dc:publisher>Random House, Inc.</dc:publisher>
        <dc:identifier opf:scheme="ISBN">9780345418913</dc:identifier>
        <dc:language>en</dc:language>
        <dc:subject>Science-Fiction</dc:subject>
    </metadata>
    <guide>
        <reference href="Hitchhiker's Guide to the Galaxy, The - Douglas Adams.jpg" type="cover" title="Cover"/>
    </guide>
</package>
.

È stato utile?

Soluzione

Hai dimenticato l'elemento Metadati, ad esempio.

$package = simplexml_load_file('hitchhiker.opf');
echo $package->metadata->children('dc', true)->title;
.

Uscita: la guida di Hitchhiker alla galassia

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top