我是actionscript的新手。有没有人可以帮我从下面的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>♫</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'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>部分提到的样式中的值
发布于 2012-09-11 15:41:04
这是因为您的属性以名称空间为前缀,因此您必须为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());http://wonderfl.net/c/ptNa上的实况示例
在Adobe channel上使用xml命名空间的文章:http://cookbooks.adobe.com/post_Accessing_XML_attributes_and_nodes_with_different-16316.html
发布于 2012-09-11 14:30:59
这段代码将帮助您解析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]);
}
}https://stackoverflow.com/questions/12362960
复制相似问题