整数名访问XML节点 [英] Access XML nodes with integer names

查看:139
本文介绍了整数名访问XML节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关我的申请,我做的HTT prequest,并取回一些XML服务从一个JSP。该XML具有一定的(是的,我知道这是无效/不正确的XML如果我不能找到一个绷带,我会尽量解决在内部。)与整数节点的名称,说< 2 - ; 为例。

当我试图访问它,使用 myXMLVariable.child(2),则返回第三个(指数= 2)XML节点代替。据我所知,这种行为是正确的 。有什么办法可以解决这个问题?


示例

  VAR与myXML:字符串=<响应>中+
                    &其中; PLACE1>中+
                    <项目> 1< /项目>中+
                    &其中;东西→1&其中; /东西>中+
                    &所述; / PLACE1>中+
                    2>中+
                    <项目> 1< /项目>中+
                    &其中;东西→1&其中; /东西>中+
                    &所述; / 2>中+
                    &其中; place3>中+
                    <项目> 1< /项目>中+
                    &其中;东西→1&其中; /东西>中+
                    &所述; / place3>中+
                    &所述; /响应>中;

保护功能getParam():无效
{
    VAR的xml:XML =新的XML(与myXML);

    Alert.show(xml.child(2));
    //trace(xml.child("2))
}
 

xml.child(2)返回

 < place3>
    ...
< / place3>
 

...当我想

  2>
    ...
&所述; / 2  - ;
 


注意

我知道这是无效的XML。我要寻找一个解决办法,短期修复。有一个近未来的发布日期,而这种解决办法将被删除,并用正确的XML的下一个版本取代。

解决方案

使用E4X搜索前就返回XMLList pression。

 跟踪(xml.children()(名()==2)toXMLString());
 

  1. 在获取所有的孩子
  2. 搜索您需要的名称()。

For my application, I make an HTTPRequest, and get back some XML served from a JSP. That XML has some (yes, I'm aware this is invalid/improper XML. If I can't find a bandaid, I will try to address that internally) nodes with integers as names, say <2> for example.

When I attempt to access it, using myXMLVariable.child("2"), it returns the third (index=2) XML node instead. I understand that this behavior is "correct". Is there any way to get around this behavior?


Example

var myXML:String = "<response>" +
                    "<place1>" +
                    "   <item>1</item>" +
                    "   <stuff>1</stuff>" +
                    "</place1>" +
                    "<2>" +
                    "   <item>1</item>" +
                    "   <stuff>1</stuff>" +
                    "</2>" +
                    "<place3>" +
                    "   <item>1</item>" +
                    "   <stuff>1</stuff>" +
                    "</place3>" +
                    "</response>";

protected function getParam():void
{
    var xml:XML = new XML(myXML);

    Alert.show(xml.child("2"));
    //trace(xml.child("2"))
}

xml.child("2") returns

<place3>
    ...
</place3>

...when I want

<2>
    ...
</2>


NOTE

I am aware this is invalid XML. I am looking for a workaround, a short term fix. There is a near-future release date, and this workaround will be removed and replaced with proper XML for the next version.

解决方案

Use E4X search expression on XMLList.

trace(xml.children().(name() == "2").toXMLString());

  1. Get all children
  2. Search for the name() you need.

这篇关于整数名访问XML节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆