0

I have a yxz.xml file with the following content:

<x:xmpmeta xmlns:x="adobe:ns:meta/"
    x:xmptk="Adobe XMP Core 6.0-c005 79.164590, 2020/12/06-10:37:24        ">
    <rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        <rdf:Description
            xmlns:xmp="http://ns.adobe.com/xap/1.0/"
            xmlns:dc="http://purl.org/dc/elements/1.1/"
            xmlns:aux="http://ns.adobe.com/exif/1.0/aux/"
            xmlns:exifEX="http://cipa.jp/exif/1.0/"
            xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
            xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
            xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
            xmlns:stRef="http://ns.adobe.com/xap/1.0/sType/ResourceRef#"
            rdf:about="" xmp:Rating="1"
            xmp:ModifyDate="2021-01-02T08:30:15+02:00"
            xmp:CreateDate="2020-03-16T09:12:03"
            xmp:MetadataDate="2021-02-02T08:24:16+06:00"
            xmp:CreatorTool="Adobe Photoshop 20.4 (Windows)"
            dc:format="image/jpeg" aux:SerialNumber="039138000900"
            aux:LensInfo="400/1 400/1 0/0 0/0" aux:Lens="Canon 400mm Lens"
            aux:LensID="174" aux:LensSerialNumber="0000000000"
            aux:ImageNumber="0" aux:ApproximateFocusDistance="676/100"
            aux:FlashCompensation="0/1" aux:OwnerName="John Doe"
            aux:Firmware="1.2.1" exifEX:LensModel="Canon 400mm lens"
            photoshop:DateCreated="2019-06-10T11:11:07.045"
            photoshop:LegacyIPTCDigest="49BDFEREFDSFG18CD16CACC5E64854"
            xmpMM:DocumentID="xmp.did:74FE0B7A62DE11EBEBHDG5U7FSE642A4"
            xmpMM:OriginalDocumentID="D31C0FB3419167BE41B5382649423449"
            xmpMM:InstanceID="xmp.iid:74FE0B7962DE11EBB4A0ABFFFFFFFA4">
            <dc:creator>
                <rdf:Seq>
                    <rdf:li>John Doe</rdf:li>
                </rdf:Seq>
            </dc:creator>
            <dc:rights>
                <rdf:Alt>
                    <rdf:li xml:lang="x-default">All rights reserved</rdf:li>
                </rdf:Alt>
            </dc:rights>
            <photoshop:DocumentAncestors>
                <rdf:Bag>
                    <rdf:li>xmp.did:9713f9f9-650f-4f88-kas9-5a516d4e11ef</rdf:li>
                </rdf:Bag>
            </photoshop:DocumentAncestors>
            <xmpMM:History>
                <rdf:Seq>
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:8fc0ec65-794c-23d8-90d4-2fdaa6e34f82"
                        stEvt:when="2020-01-23T17:28:12+02:00"
                        stEvt:softwareAgent="Adobe Photoshop Camera Raw 12.1"
                        stEvt:changed="/metadata" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:d0d911db-71b2-4274-674b-4823d2b1dab4"
                        stEvt:when="2020-02-10T11:28:19+02:00"
                        stEvt:softwareAgent="Adobe Photoshop Camera Raw 12.1 (Windows)"
                        stEvt:changed="/metadata" />
                    <rdf:li stEvt:action="derived"
                        stEvt:parameters="converted from image/x-canon-cr2 to image/tiff" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                        stEvt:when="2020-01-01T23:18:16+02:00"
                        stEvt:softwareAgent="Adobe Photoshop Camera Raw 13.1 (Windows)"
                        stEvt:changed="/" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                        stEvt:when="2020-01-02T19:13:13+02:00"
                        stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)"
                        stEvt:changed="/" />
                    <rdf:li stEvt:action="converted"
                        stEvt:parameters="from image/tiff to application/vnd.adobe.photoshop" />
                    <rdf:li stEvt:action="derived"
                        stEvt:parameters="converted from image/tiff to application/vnd.adobe.photoshop" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                        stEvt:when="2020-01-01T19:03:07+02:00"
                        stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)"
                        stEvt:changed="/" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                        stEvt:when="2021-01-01T01:03:08+011:00"
                        stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)"
                        stEvt:changed="/" />
                    <rdf:li stEvt:action="converted"
                        stEvt:parameters="from application/vnd.adobe.photoshop to image/jpeg" />
                    <rdf:li stEvt:action="derived"
                        stEvt:parameters="converted from application/vnd.adobe.photoshop to image/jpeg" />
                    <rdf:li stEvt:action="saved"
                        stEvt:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                        stEvt:when="2001-01-01T01:43:11+03:00"
                        stEvt:softwareAgent="Adobe Photoshop 22.1 (Windows)"
                        stEvt:changed="/" />
                </rdf:Seq>
            </xmpMM:History>
            <xmpMM:DerivedFrom
                stRef:instanceID="xmp.iid:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                stRef:documentID="adobe:docid:photoshop:97f341c8-320f-4d28-kak9-5b917f4e11ff"
                stRef:originalDocumentID="D31C0FB34245A4B764F23EB6D25CEE49" />
        </rdf:Description>
    </rdf:RDF>
</x:xmpmeta>

How can I list result like:

echo aux:OwnerName
//output John Doe

echo aux:LensID
// output 174

echo aux:FlashCompensation
//output 0/1

…and other entries, with PHP?

Nigel Ren
  • 56,122
  • 11
  • 43
  • 55
Luther
  • 155
  • 1
  • 2
  • 7
  • You could search with SimpleXML usage – bklups Feb 12 '21 at 16:15
  • SimpleXML cannot create object, possibly I'm used wrong way. Please show me your solution! – Luther Feb 12 '21 at 16:29
  • Try SimpleXMLElement combined to XPath – bklups Feb 12 '21 at 16:33
  • [Parsing nested XML/RDF] (https://stackoverflow.com/a/10067812/2331686) – bklups Feb 12 '21 at 16:38
  • ```$xml = new SimpleXMLElement($xmp_data); $xml->registerXPathNamespace('rdf', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'); $lens_id = $xml->xpath('rdf:Description/aux:LensID'); print_r($lens_id);``` Gives no output, just two warning messages: Undefined namespace prefix in… and xmlXPathEval: evaluation failed in – Luther Feb 12 '21 at 17:31
  • Use a library for the specific format like [XMPReader](https://github.com/wikimedia/xmp-reader). – ThW Feb 13 '21 at 11:08

1 Answers1

0

It's simpler to do it this way:

$doc = new DOMDocument;
$doc->loadxml($xmp_data);
$xpath = new DOMXPath($doc);
$xpath->registerNamespace('aux', 'http://ns.adobe.com/exif/1.0/aux/');

echo $xpath->query('//@aux:OwnerName')[0]->nodeValue ."\n";
echo $xpath->query('//@aux:LensID')[0]->nodeValue ."\n";
echo $xpath->query('//@aux:FlashCompensation')[0]->nodeValue;

Output:

John Doe
174
0/1
Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45