2

所以我正在开发一个快速实用程序来允许对 TMX 文件进行简单的编辑。TMX 基本上是一种基于 XML 的标准,用于存储多语言翻译。无论如何,我正在通过文件引用将 TMX 导入 Adob​​e AIR 应用程序,然后获取文件流,将 UTF-8 字符转换为字符串,然后将该字符串转换为 XML 对象。因此:

var stream:FileStream = new FileStream();
stream.open(event.target /*file data*/ as File, FileMode.READ);
var fileData:String = stream.readUTFBytes(stream.bytesAvailable);
var tmxXml:XML = new XML(fileData);

但是,这是有趣的部分。如果fileData这样加载:

<tuv xml:lang="en">
    <seg>About Us</seg>
</tuv>

Flex 的 XML 将其解释为:

<tuv aaa:lang="en" xmlns:aaa="http://www.w3.org/XML/1998/namespace">
    <seg>
        About Us
    </seg>
</tuv>

哦嗬有趣!属性xml:lang变为aaa:lang="en" xmlns:aaa="http://www.w3.org/XML/1998/namespace"。根据我的简短研究,发生这种情况有一些先例,但这有点糟糕的假设。在不创建过多的字符串替换规则的情况下,有没有办法规避这种情况?

4

2 回答 2

1

Sorry, can't comment (yet?) so I'll put this here.

I can replicate when adding a non-default namespace to XML with a default namespace:

var node:XML = <node xmlns="http://namespacehere.org"/>
var ns:Namespace = new Namespace("xml", "http://www.w3.org/XML/1998/namespace");
node.@ns::base = "myvalue";

Output is <node aaa:base="myvalue" xmlns="http://namespacehere.org" xmlns:aaa="http://www.w3.org/XML/1998/namespace"/>

Adding use namespace ns has no effect and a default namespace is not applicable (it needs to be prefixed).

I have come accross this issue a few times, but have not been able to isolate the cause. Note: one still ends up with an "aaa" prefix no matter what prefix or URI you set in the namespace. Odd.

于 2011-09-01T14:35:24.447 回答
1

您是否尝试过使用以下方法之一?

 default xml namespace = xml;

或者,

 use namespace xml;

浏览命名空间文档。

于 2009-04-24T11:52:08.883 回答