简体   繁体   English

Actionscript 3.0中的XML解析问题

[英]XML parsing issues in Actionscript 3.0

I got a problem in parsing the following xml: 我在解析以下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: 我想要一个xmp描述列表及其值列表:

-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. 您需要为要访问的所有名称空间创建名称空间对象,并为E4X属性添加适当的名称空间作为前缀。 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 . 您也可以使用XMP库

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. 如果要访问单个属性,则可以使用XMPConst ,它提供了大多数所需的名称空间。

var xmp:Namespace = XMPConst.xmp;
trace(m.xmp::rating); //etc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM