Re: XMP Parsing Question
by Bruce Miller other posts by this author
Sep 22 2005 1:51PM messages near this date
view in the new Beta List Site
Re: XMP Parsing Question
|
Re: XMP Parsing Question
& XSLT Michael Nachbaur wrote:
> my $parser = new XML::LibXML();
> my $doc = $parser->parse_string($xmp);
> # or:
> # my $doc = $parser->parse_file($xmp_filename);
> my $rootNode = $doc->documentElement();
> my $image = $rootNode->findvalue('//xapgimg:image');
>
> Or if you want to be more specific, you can use the following for the
> last line:
> my $image =
> $rootNode->findvalue('/x:xmpmeta/rdf:rdf//xap:thumbnails//xapgimg:image');
>
> This code assumes that only one thumbnail exists. However, it should
> suffice.
Actually (I think), because there can be multiples, findnode returns
a list. Unless findnode has specially coded it (which I doubt),
in a scalar context, it will return the number of nodes found, rather than
the node. So, you'll do better with:
my ($firstimage) = $rootNode-> findvalue(..xpath...);
Incidentally, since the example is heavily using namespaces,
it will be safer to use a more convoluted xpath like:
//*[local-name()='image' and namespace-url()='whatever']
You'll probably be happier in the long run install
XML::LibXML::XPathContext and then
my $xpcontext = XML::LibXML::XPathContext-> new();
$xpcontext-> registerNs('xapgimp','whatever');
my ($firstimage)-> findvalue("//xapgimp:image", $rootNode);
> The above code illustrates using XPath to query the contents of the XML
> file. You may want to look into XPath more, because it is a very
> powerful way of interacting with XML documents, and would let you get
> more out of this document easily if you need to.
>
> Christopher Pryce wrote:
>
> > I'm not terribly good with XML yet, but I'm learning.
> >
> > How would I go about extracting the value of the <xampimg:image> tag
> > in the following XML fragment, using XML::LibXML ?
> >
> > Thanks very much.
> >
> > --
> >
> >
> > <x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="XMP toolkit 2.9.1-13,
> > framework 1.6">
> > <rdf:rdf xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
> > xmlns:ix="http://ns.adobe.com/iX/1.0/">
> > <rdf:description xmlns:pdf="http://ns.adobe.com/pdf/1.3/"
> > rdf:about="uuid:93ab74ca-923b-11d9-b281-0003934be352"
> > pdf:producer="Adobe PDF library 6.66" />
> > <rdf:description
> > xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
> > rdf:about="uuid:93ab74ca-923b-11d9-b281-0003934be352"
> > photoshop:datecreated="2005-03-11T00:00:00Z"
> > photoshop:city="Minneapolis" photoshop:state="MN"
> > photoshop:country="Hennepin" photoshop:credit="SRF Consulting Group,
> > Inc." />
> > <rdf:description xmlns:xap="http://ns.adobe.com/xap/1.0/"
> > xmlns:xapgimg="http://ns.adobe.com/xap/1.0/g/img/"
> > rdf:about="uuid:93ab74ca-923b-11d9-b281-0003934be352"
> > xap:createdate="2005-03-11T08:14:14-06:00"
> > xap:modifydate="2005-03-11T08:40:56-06:00"
> > xap:creatortool="Illustrator"
> > xap:metadatadate="2005-03-11T08:40:56-06:00">
> > <xap:thumbnails>
> > <rdf:alt>
> > <rdf:li rdf:parsetype="Resource">
> > <xapgimg:format>
> > JPEG
> > </xapgimg:format>
> > <xapgimg:width>
> > 244
> > </xapgimg:width>
> > <xapgimg:height>
> > 256
> > </xapgimg:height>
> > <xapgimg:image>
> > #### Some Binary Data that I want. ########
> > </xapgimg:image>
> > </rdf:li>
> > </rdf:alt>
> > </xap:thumbnails>
> > </rdf:description>
> > <rdf:description xmlns:xapmm="http://ns.adobe.com/xap/1.0/mm/"
> > rdf:about="uuid:93ab74ca-923b-11d9-b281-0003934be352"
> > xapmm:documentid="uuid:84758202-923b-11d9-b281-0003934be352" />
> > <rdf:description xmlns:dc="http://purl.org/dc/elements/1.1/"
> > rdf:about="uuid:93ab74ca-923b-11d9-b281-0003934be352"
> > dc:format="application/vnd.adobe.illustrator">
> > <dc:creator>
> > <rdf:seq>
> > <rdf:li>
> > Christopher Pryce
> > </rdf:li>
> > </rdf:seq>
> > </dc:creator>
> > </rdf:description>
> > </rdf:rdf>
> > </x:xmpmeta>
> >
> > _______________________________________________
> > Perl-XML mailing list
> > Perl-XML@[...].com
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>
> _______________________________________________
> Perl-XML mailing list
> Perl-XML@[...].com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
--
bruce.miller@[...].gov
http://math.nist.gov/~BMiller/
_______________________________________________
Perl-XML mailing list
Perl-XML@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Christopher Pryce
Michael Nachbaur
Christopher Pryce
Bruce Miller
Michael Nachbaur
|