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