Extracting XMP data and JAXB
in
Programming Questions
•
1 year ago
Hi all,
I'm currently trying to use JAXB to read XMP data extracted from image files. I'm basing this on the tutorial here: http://wiki.processing.org/w/XML_parsing_with_JAXB
Getting the XMP data from the file is fine. An example of the data I'm getting is:
However when I try to unmarshal this into objects it fails due to the namespace prefixes. The error I get is:
javax.xml.bind.UnmarshalException: unexpected element (uri:"adobe:ns:meta/", local:"xmpmeta"). Expected elements are <{}xmpmeta>
If I manipulate the XMP data as a string string to remove the namespace prefixes e.g. <x:xmpmeta /> become <xmpmeta /> then it works, but this is pretty unreliable as I keep encountering new namespaces as I try different files and basically this just doesn't seem to be the 'right' way to go about it.
Any pointers on how to handle the namespace prefixes in JAXB, as I'm failing to get to the bottom of it at the moment!
Cheers
Phil
I'm currently trying to use JAXB to read XMP data extracted from image files. I'm basing this on the tutorial here: http://wiki.processing.org/w/XML_parsing_with_JAXB
Getting the XMP data from the file is fine. An example of the data I'm getting is:
- <x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:subject><rdf:Bag xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Hong Kong</rdf:li><rdf:li>Asia</rdf:li><rdf:li>Market</rdf:li><rdf:li>Night</rdf:li></rdf:Bag></dc:subject></rdf:Description><rdf:Description rdf:about="uuid:faf5bdd5-ba3d-11da-ad31-d33d75182f1b" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:creator><rdf:Seq xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Phil Larby</rdf:li></rdf:Seq></dc:creator><dc:title><rdf:Alt xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li xml:lang="x-default">Temple Street Night Market</rdf:li></rdf:Alt></dc:title><dc:description><rdf:Alt xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li xml:lang="x-default">Temple Street Night Market</rdf:li></rdf:Alt></dc:description></rdf:Description><rdf:Description xmlns:MicrosoftPhoto="http://ns.microsoft.com/photo/1.0/"><MicrosoftPhoto:LastKeywordXMP><rdf:Bag xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><rdf:li>Hong Kong</rdf:li><rdf:li>Asia</rdf:li><rdf:li>Market</rdf:li><rdf:li>Night</rdf:li></rdf:Bag></MicrosoftPhoto:LastKeywordXMP></rdf:Description></rdf:RDF></x:xmpmeta>
However when I try to unmarshal this into objects it fails due to the namespace prefixes. The error I get is:
javax.xml.bind.UnmarshalException: unexpected element (uri:"adobe:ns:meta/", local:"xmpmeta"). Expected elements are <{}xmpmeta>
If I manipulate the XMP data as a string string to remove the namespace prefixes e.g. <x:xmpmeta /> become <xmpmeta /> then it works, but this is pretty unreliable as I keep encountering new namespaces as I try different files and basically this just doesn't seem to be the 'right' way to go about it.
Any pointers on how to handle the namespace prefixes in JAXB, as I'm failing to get to the bottom of it at the moment!
Cheers
Phil
1