写,更新和保存在AS3一个良好的XML文件 [英] write, update and save a well-formed xml file in as3

查看:298
本文介绍了写,更新和保存在AS3一个良好的XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想更新XML文件和保存一个已经保存的根元素的元素

I am trying to update an xml file and save elements inside of an already saved root element.

我才发现,那里的XML文件是刚开业,而不是保存的例子。谁能帮我找到保存结果的最佳方式是什么?

I have only found examples where the xml files are just opened and not saved. Can someone help me to find the best way to save the results?

我的项目现在看起来是这样的:

My project right now looks like this:

我加载通过的URLLoader /的URLRequest一个XML文件,并在多个文本字段显示的内容。从输入领域的新文本保存(附加),通过直接的FileStream在applicationStorageDirectory xml文件(这将是在iPhone上)。

I am loading an xml file via URLLoader/URLRequest and display the contents in several text fields. New text from an input field is saved (appended) via FileStream directly to the xml file in the applicationStorageDirectory (that will be on iPhone).

新的输入应该被添加到一个屏幕上的列表和显示,但是,它不能得到它远远(带有一个for循环创建)。从XML文件中读取新保存输入后,我自然会得到错误1088,因为XML文件格式不正确了。

The new input should then be added to an on-screen list (created with a for-loop) and displayed, however, it can't get it that far. After reading the newly saved input from the xml file, I naturally get error 1088 because the xml file is not well-formed anymore.

这是因为输入的是根元素之后添加,结果是这样的:

This is because the input is appended after the root element and the result looks like this:

<root>
  <message></message>
  <date></date>
</root>
  <message>new input</message>
  <date></date>

当然,当我要的是这样的:

When of course what I want is this:

<root>
  <message></message>
  <date></date>
  <message>new input</message>
  <date></date>
</root>

但我不知道我如何能做到这一点。

But I have no idea how i can achieve that.

我几次试图避免追加,像加载XML内容,改变它,然后重新写的一切。但自从我还是新的AS3我无法得到它的工作。

I made several attempts to avoid having to append, like loading the xml content, changing it, and then writing everything again. But since I am still new to as3 I couldn't get it to work.

这将是巨大的,如果有人能告诉我怎么走会,也许如何解决它的最好办法。

It would be great if someone could tell me what the best way to go would be and maybe how to solve it.

推荐答案

那岂不是更简单地使用XML文本的工作?

Wouldn't it be better to simply work with XML literals?

package
{
  import flash.display.Sprite;

  public class ZutAlors extends Sprite
  {
    public function ZutAlors()
    {
      trace(messagesToXMLString('hello world'.split(' ')));
    }

    private function messageToXML(m:String, d:Date = null):XMLList
    {
      return <ret>
        <message>{m}</message>
        <date>{(d || new Date()).toString()}</date>
      </ret>.children();
    }

    private function messagesToXMLString(array:Array):XML
    {
      const ret:XML = <root />
      for each(var s:String in array)
      {
        ret.appendChild(messageToXML(s));
      }
      return ret;
    }
  }
}

您得到一个编译错误,如果XML不是简洁(wellformed)...

You get a compile error if the XML was not wellformed ...

这篇关于写,更新和保存在AS3一个良好的XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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