0

我是动作脚本的新手。任何人都可以帮助我尝试从以下 XML 中获取值timed text format

<?xml version="1.0" encoding="UTF-8"?>
<tt xml:lang="en"
    xmlns:tts="http://www.w3.org/2006/10/ttaf1#styling"
    xmlns:ttm="http://www.w3.org/2006/10/ttaf1#metadata"
    xmlns:smpte="http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt"
    xmlns:m608="http://www.smpte-ra.org/schemas/2052-1/2010/smpte-tt#cea608">
   <head>
      <ttm:title>SCCconvert </ttm:title>
      <ttm:desc>converted document; </ttm:desc>
      <ttm:copyright>Copyright (C) Computer Prompting and Captioning Co.</ttm:copyright>
      <styling>
      <style xml:id='basic' tts:color='white' tts:fontFamily='proportionalSansSerif' 
            tts:lineHeight='8%' 
            tts:fontSize='8%' 
            tts:fontWeight='bold'
            tts:textOutline='black 8% 8%' />
      </styling>
      <layout>
         <region xml:id='pop1' tts:backgroundColor='transparent'></region>
         <region xml:id='pop2' tts:backgroundColor='blue'></region>
       </layout>
   </head>
   <body>
      <div>
         <p region='pop1' style='basic' xml:space='preserve' begin='00:00:02:05' end='00:00:06:16' tts:origin='47% 10%'>
            <span>♫&lt;/span>
         </p>
         <p region='pop1' style='basic' xml:space='preserve' begin='00:00:06:16' end='00:00:08:05' tts:origin='27% 84%'>
            <span>I can&apos;t do this!</span>
         </p>
         <p region='pop2' style='basic' xml:space='preserve' begin='00:00:08:05' end='00:00:09:17' tts:origin='10% 78%'>
            <span>You fail because</span>
         </p>
        </div>
   </body>
</tt>

如果 XML 值是正常格式,我可以读取它。但我需要以本<layout>节中提到的样式显示值

4

2 回答 2

1

这是因为您的属性以命名空间为前缀,因此您必须为 ttm、tts 等创建一个新的命名空间,然后使用它来访问该属性。

访问 layout.region 节点内所有 backgroundColor 的示例:

// namespace creation for tts
var tts:Namespace=new Namespace("http://www.w3.org/2006/10/ttaf1#styling");

// and use of the namespace tts for accessing the attribute
// @my_namespace::my_attribute
trace(xml..layout.region.@tts::backgroundColor.toXMLString());

Wonderfl 上的实时示例:http ://wonderfl.net/c/ptNa

在 Adob​​e 频道上使用 xml 命名空间的文章:http: //cookbooks.adobe.com/post_Accessing_XML_attributes_and_nodes_with_different-16316.html

于 2012-09-11T07:41:04.117 回答
0

这段代码将帮助您解析 xml。

import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;


var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onXMLLoaded);
loader.load(new URLRequest("style.xml"));

function onXMLLoaded(e:Event){
    loader.removeEventListener(Event.COMPLETE, onXMLLoaded);

    var xml:XML = new XML(loader.data);

    var xlist:XMLList = xml.head.layout.child("region");

    for(var i=0;i<xlist.length();i++){
        trace("--->"+xlist[i].attributes()[0]);
        trace("--->"+xlist[i].attributes()[1]);
    }
}
于 2012-09-11T06:30:58.947 回答