更改的XML内容 [英] Changing content of XML

查看:143
本文介绍了更改的XML内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个 XML 文件,它由不同的节点。我需要改变其中一个节点属性,然后覆盖一切,一个新的版本。我发现<一href="http://stackoverflow.com/questions/6704028/as3-access-variable-when-writing-xml-$c$c-directly-in-as3">that SO问题,但的Flash IDE 无法了解我的XML文件,同时,并抛出关于语法错误。

我在节目中的计算,应写在XML特定的属性。然后将文件的更新版本,与前(覆盖)所取代。

我的XML文件是巨大的,复杂的,因此我无法把我所有的codeS在这里。不过,我可以告诉你,我得到一切从文件,并把那些在code像上面的链接。

?<?pre> &LT; XML版本=1.0编码=UTF-8&GT;&LT;! - 我想这部分是无法识别的,需要之前添加保存 - &GT; &所述;东西X =0Y =0宽度=1437.5高度=1010&GT;

Flash需要一个; X =0键,果然停止

什么是正确的方法来改变一个XML的属性?


编辑:

我使用一个数组为XML文件通过切片成片。然后,添加必要的零件,并保持这样的。但我不知道有没有这样做,而不使用数组搞乱的更好的方法。

解决方案

要改变一个XML属性,可以使用的 E4X 用于XML的ECMAScript ),像这样的:

  VAR的xml:XML =&LT;对象&GT;
    &所述;对象的id =mc_01×=0Y =0宽度=1437.5高度=1010/&GT;
    &所述;对象的id =mc_02×=300Y =400宽度=150的高度=100/&GT;
    &所述;对象的id =mc_03×=120Y =0宽度=50高度=30/&GT;
&LT; /对象取代;

//其ID(例如)选择对象,并更改其X属性
。XML *(@ ID =='mc_02)@ X = 800。

跟踪(XML);

//给
//
//&LT;对象&GT;
//&所述;对象的id =mc_01×=0Y =0宽度=1437.5高度=1010/&GT;
//&所述;对象的id =mc_02×=800Y =400宽度=150的高度=100/&GT;
//&所述;对象的id =mc_03×=120Y =0宽度=50高度=30/&GT;
//&LT; /对象&GT;
 

有关更多关于XML在ActionScript 3的工作,看看这里

希望能有所帮助。

There is an XML file and it consists of various nodes. I need to change one attribute of the nodes and then overwrite everything as a new version. I have found that SO question but Flash IDE cannot understand my XML file at all and throw errors about syntax.

I have calculations during the programme and should be written in specific attribute in XML. Then the updated version of the file replaced with former (overwrite).

My XML file are huge and complex, thus I am unable to put all my codes here. However I can tell you that I get everything from the file and put those in the code like link above.

<?xml version="1.0" encoding="UTF-8"?><!--I guess this part is not recognised and need to be added just before to save-->
<Something x="0" y="0" width="1437.5" height="1010">

Flash expects a ; after the x="0" and stops expectedly.

What is the proper way to change the attribute of an XML?


Edit:

I am using an array for the XML file by slicing into pieces. Then I add necessary parts and keep like that. But I wonder is there better way of doing it without messing with arrays.

解决方案

To change an XML attribute, you can use E4X ( ECMAScript for XML ), like this :

var xml:XML = <objects>
    <object id="mc_01" x="0" y="0" width="1437.5" height="1010" />
    <object id="mc_02" x="300" y="400" width="150" height="100" />
    <object id="mc_03" x="120" y="0" width="50" height="30" />
</objects>;

// select the object with its id (for example), and change its "x" attribute
xml.*.(@id == 'mc_02').@x = 800;

trace(xml);

// gives
//
//  <objects>
//    <object id="mc_01" x="0" y="0" width="1437.5" height="1010"/>
//    <object id="mc_02" x="800" y="400" width="150" height="100"/>
//    <object id="mc_03" x="120" y="0" width="50" height="30"/>
//  </objects>

For more about working with XML in ActionScript 3, take a look here.

Hope that can help.

这篇关于更改的XML内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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