So I'm working on a quick utility to allow simple editing for TMX files. TMX is basically an XML-based standard for storing multilingual translations. Anyhoo, I'm importing TMX into an Adobe AIR app via a File reference, then grabbing the file stream, slapping the UTF-8 characters into a string, and then that string into an XML object. THus:
所以我正在开发一个快速实用工具,允许简单编辑TMX文件。 TMX基本上是一种基于XML的标准,用于存储多语言翻译。 Anyhoo,我通过File引用将TMX导入Adobe 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);
But, here is the interesting part. If fileData
is loaded as this:
但是,这是有趣的部分。如果fileData加载如下:
<tuv xml:lang="en">
<seg>About Us</seg>
</tuv>
Flex's XML interprets it as this:
Flex的XML将其解释为:
<tuv aaa:lang="en" xmlns:aaa="http://www.w3.org/XML/1998/namespace">
<seg>
About Us
</seg>
</tuv>
Oh ho interesting! The attribute xml:lang
becomes aaa:lang="en" xmlns:aaa="http://www.w3.org/XML/1998/namespace"
. From my brief research, there is some precedent for this happening, but it's somewhat a sucky assumption. Without creating excessive string replace rules, is there a way to circumvent this?
哦,有趣!属性xml:lang变为aaa:lang =“en”xmlns:aaa =“http://www.w3.org/XML/1998/namespace”。从我的简短研究来看,这种情况有一些先例,但这有点像一个糟糕的假设。如果没有创建过多的字符串替换规则,有没有办法绕过这个?
2 个解决方案
#1
Have you tried using one of the following?
您是否尝试过使用以下哪种方法?
default xml namespace = xml;
or,
use namespace xml;
Go through the Namespaces documentation.
浏览命名空间文档。
#2
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:
在使用默认命名空间向XML添加非默认命名空间时,我可以复制:
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).
添加use namespace ns无效,默认命名空间不适用(需要加前缀)。
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.
我曾几次遇到这个问题,但未能找出原因。注意:无论您在命名空间中设置了什么前缀或URI,都会以“aaa”前缀结尾。奇。
#1
Have you tried using one of the following?
您是否尝试过使用以下哪种方法?
default xml namespace = xml;
or,
use namespace xml;
Go through the Namespaces documentation.
浏览命名空间文档。
#2
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:
在使用默认命名空间向XML添加非默认命名空间时,我可以复制:
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).
添加use namespace ns无效,默认命名空间不适用(需要加前缀)。
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.
我曾几次遇到这个问题,但未能找出原因。注意:无论您在命名空间中设置了什么前缀或URI,都会以“aaa”前缀结尾。奇。