【问题标题】:Actionscript : Timed text format xmlActionscript : 定时文本格式 xml
【发布时间】:2012-09-11 04:53:42
【问题描述】:

我是 actionscript 的新手。谁能帮我尝试从以下timed text format 中的 XML 获取值:

<?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>♫</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 值是正常格式,我可以读取它。但我需要以&lt;layout&gt; 部分中提到的样式显示值

【问题讨论】:

    标签: actionscript-3 flash


    【解决方案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

    【讨论】:

      【解决方案2】:

      这段代码将帮助你解析你的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]);
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-04-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-28
        相关资源
        最近更新 更多