Thanks Maurice,
worked like a charm!
For those who also encounter such a question , full function to read and
trace an specfifc part of the XML file:
* 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 <http://www.idpf.org/2007/opf>")*
* var nsdc: Namespace = new Namespace("dc",
"http://purl.org/dc/elements/1.1/ <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());*
* }*
Again, must have tried a number of variations on a theme and this answer
was just what I needed.
Thaks for great (and prompt support).
Now if only my cat would get away from my keyboard:-)
Phil.
On Sun, Apr 13, 2014 at 3:13 PM, Maurice Amsellem <
[email protected]> wrote:
> You need to add the namespaces (using addNamespace) , since your xml has
> namespaces
>
> This is something that works:
>
> 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());
>
> HTH;
>
> Maurice
>
> -----Message d'origine-----
> De : Maurice Amsellem [mailto:[email protected]]
> Envoyé : dimanche 13 avril 2014 16:04
> À : [email protected]
> Objet : RE: Trouble with Flex Desktop accessing XML file with namespace
> elements
>
> This might help:
>
>
> http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7e6c.html
>
> Note: you don't need the second conversion from XML to XMList. If you
> use directly the first XML, it will not have the aaa namespace.
>
> HTH
>
> Maurice
>
> -----Message d'origine-----
> De : Philip Medlam [mailto:[email protected]] Envoyé : dimanche 13
> avril 2014 14:40 À : [email protected] Objet : Trouble with Flex
> Desktop accessing XML file with namespace elements
>
> HI,
>
> * I have an XML file (actually an epub contentes.opf file) partially shown
> as follows:*
>
> <?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
>
> *I read the file as:*
>
> str = XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
> var xmlList:XMLList = XMLList (str);
>
> *My xmlList trace *
>
> trace(xmlList);
>
> *now shows (seems to have added a default namespcae - not too bothered by
> this):*
>
> <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>
>
> *How can I access an element from the xmlList (say title)?*
>
> *Tried quite a few variation, so this is driving me a bit nuts and help
> would be appreciated.*
>
>
> *Thanks for any help!*
>
>
> Phil
>
--
Philip Medlam