我有一个XML文件(实际上是一个epub contentes.opf文件)部分显示如下:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="bookid" version="2.0">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<meta name="generator" content="Adobe InDesign 9.0" />
<meta name="cover" content="x22305.png" />
<dc:title>My Title</dc:title>
<dc:creator>The Author</dc:creator>
etc
我将文件读作:
str = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
var xmlList:XMLList = XMLList (str);
我的xmlList跟踪
trace(xmlList);
现在显示(似乎添加了一个默认的namespcae - 不会因此而烦恼):
<aaa:package unique-identifier="bookid" version="2.0" xmlns:aaa="http://www.idpf.org/2007/opf">
<aaa:metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<aaa:meta name="generator" content="Adobe InDesign 9.0"/>
<aaa:meta name="cover" content="x22305.png"/>
<dc:title>My Title</dc:title>
<dc:creator>The Author</dc:creator>
如何从xmlList访问元素(比如标题)?
尝试了不少变化,所以这让我有点疯狂,并且会感激不尽。
感谢您的帮助!
答案 0 :(得分:0)
感谢flex小组中的一个小伙子的帮助,解决方案是(对于那些有类似问题的人):
private function contentsOpf():void
{
var contentsOpfFile:File = new File(destDir.nativePath + File.separator + "OEBPS" + File.separator + "content.opf");
var fileStream:FileStream = new FileStream();
fileStream.open(contentsOpfFile, FileMode.READ);
var ns: Namespace = new Namespace("","http://www.idpf.org/2007/opf")
var nsdc: Namespace = new Namespace("dc", "http://purl.org/dc/elements/1.1/") ;
var packageXml: XML = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
packageXml.addNamespace(ns);
var metadataXml: XMLList = packageXml.ns::metadata;
metadataXml.addNamespace(nsdc);
var titleXml: XMLList = metadataXml.nsdc::title;
trace(packageXml.toString());
trace(titleXml.toString());
}
菲尔