简体   繁体   English

将XML加载到Flex AS3中

[英]Loading XML into Flex AS3

I am trying to be able to load all XML data from an XML document and have been failing all night on it even with research 我试图能够从XML文档中加载所有XML数据,即使经过研究,整夜都失败了

Here is a snippet of the XML I am trying to load: 这是我要加载的XML的片段:

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <id>urn:uuid:5762c9e8-4e65-3b0c-83b3-7874683f3dbe</id>
  <link href="/v1/espi_third_party_batch_feed" rel="self">
  </link>
  <title type="text">Opower ESPI Third Party Batch Feed v1</title>
  <updated>2012-04-03T22:55:36.364Z</updated>

  <entry>
    <id>urn:uuid:baa6a50a-1306-3680-80a4-51d228db8f25</id>
    <link href="/v1/User/3560606/UsagePoint/6403112/MeterReading/1/IntervalBlock/1" rel="self">
    </link>
    <content type="xml">
      <IntervalBlock xmlns="http://naesb.org/espi">
        <interval>
          <duration>3600</duration>
          <start>1299128400</start>
        </interval>
        <IntervalReading>
          <timePeriod>
            <duration>3600</duration>
            <start>1299128400</start>
          </timePeriod>
          <value>436</value>
        </IntervalReading>
      </IntervalBlock>
    </content>
  </entry>
</feed>

Here is a snippet of the AS3 code I am puzzled on in the XmlLoader: 这是XmlLoader中令人困惑的AS3代码的片段:

    public function returnArray():Array
    {           
        var ATOM:Namespace = new Namespace("http://www.w3.org/2005/Atom");
        var NAESB:Namespace = new Namespace("http://naesb.org/espi");
        trace("entered returnArray");
        var tempArray:Array = new Array();
        var x:Number = 0;
        var y:Number = 0;
        var entries = this.docXML.ATOM::entry;
        trace(entries.length());                //returns 4 and supposed to
        trace(entries[3].content.length());     //returns 0 supposed to return 1
        trace(this.docXML.ATOM::entry[3].content.NAESB::interval.length()); //returns 0`enter code here`

First, you should take a look at the documentation for e4x . 首先,您应该查看e4x的文档 Secondly: what are you exactly trying to do? 其次:您到底想做什么?

The last line you could change to this.docXML.ATOM::entry.content..NAESB::interval.length() but I'm not sure what you're really trying to get out of the xml document. 您可以将最后一行更改为this.docXML.ATOM::entry.content..NAESB::interval.length()但我不确定您实际上是想摆脱xml文档的内容。 Getting the length of a node is not very useful for getting actual data out of an xml file. 获取节点的长度对于从xml文件中获取实际数据不是很有用。

The answer to this thanks frankhermes and www.Flextras.com for aiding my learning is in order to continue to traverse there is the need to add another namespace of ATOM into the xml to keep traversing 感谢frankhermes和www.Flextras.com的帮助我的学习的答案是,为了继续遍历,需要在XML中添加另一个ATOM命名空间以保持遍历。

var entries = this.docXML.ATOM::entry;
trace(entries[3].content.length()); 

should be 应该

var entries = this.docXML.ATOM::entry;
trace(entries[3].ATOM::content.length()); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM