I got a problem in parsing the following xml:
<x:xmpmeta x:xmptk="Adobe XMP Core 5.0.0-ac001" xmlns:x="adobe:ns:meta/">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about="" xmp:rating="4" xmp:title="random" xmp:land="stuff"
xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/"/>
</rdf:RDF>
</x:xmpmeta>
I would like to have a list of xmp's description and a list of its values:
-rating -title -land
and
-4 -random -stuff
I tried different parsings but no success because of the colons.
Thanks a lot for any suggestion!
You need to create Namespace objects for all the namespaces you want to access, and prefix your E4X properties with the appropriate namespaces. Here is an example of how you could read values and iterate over attributes:
var xmlString:String =
'<x:xmpmeta x:xmptk="Adobe XMP Core 5.0.0-ac001" xmlns:x="adobe:ns:meta/">\
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">\
<rdf:Description rdf:about="" xmp:rating="4" xmp:title="random" xmp:land="stuff" \
xmlns:xmp="http://ns.adobe.com/xap/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/"/>\
</rdf:RDF>\
</x:xmpmeta>';
var rdf:Namespace = new Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#');
var xmp:Namespace = new Namespace('http://ns.adobe.com/xap/1.0/');
var xml:XML = new XML(xmlString);
for each (var description:XML in xml.rdf::RDF.rdf::Description) {
var rating:String = description.@xmp::rating;
var title:String = description.@xmp::title;
var land:String = description.@xmp::land;
trace(rating, title, land);
// iterate over all the attributes
for each (var attr:XML in description.attributes()) {
trace(attr.name(), attr.localName());
}
}
You can also use the XMP Library .
var m:XMPMeta = new XMPMeta(xml);
for each (var prop:XMPProperty in m)
{
trace(prop.qname.localName);
}
for each (var value:XMPProperty in m)
{
trace(value);
}
// traces
rating
title
land
4
random
stuff
If you want to access individual properties you can you use XMPConst which provides most of the namespaces needed.
var xmp:Namespace = XMPConst.xmp;
trace(m.xmp::rating); //etc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.