为什么动作脚本只将一段字符串分配给变量?
我有一个 XML 文档,我必须将其硬编码到 AS 中(是的,我必须这样做)。我试图将此 xml 分配给一个字符串,但由于某种原因分配了 xml 文档声明?!
var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8"?>';
xmlDoc += '<?dctm xml_app=" ......
当我追踪 xmlDoc 字符串时,我总是只得到“”
我尝试将整个文档放入一个由 ' 包围的字符串中,并像上面那样连接该字符串。为什么字符串 var 只分配给第一行?
当尝试直接从文件加载 xml 文档时,我得到了相同的结果
var xmlDocument:XML = new XML();
xmlDocument.load("myxml.xml");
xmlDocument.onLoad(success:Boolean)
{
if(success)
{
trace(xmlDocument.toString()); //Just the first line is printed
}
}
谢谢
I have a XML document that I have to hard-code into AS (Yes, I HAVE to). I am trying to assign this xml to a string but for some reason on the xml doc declaration is assigned?!
var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8"?>';
xmlDoc += '<?dctm xml_app=" ......
When I trace out the xmlDoc string I always only get "<?xml version="1.0" encoding="UTF-8"?>"
I have tried putting the whole document in one string surrounded by 's and concatinating the string like above. Why is the string var only getting assigned to the first line?
I get the same result when trying to load the xml document directly from file
var xmlDocument:XML = new XML();
xmlDocument.load("myxml.xml");
xmlDocument.onLoad(success:Boolean)
{
if(success)
{
trace(xmlDocument.toString()); //Just the first line is printed
}
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不把它赋给一个 XML 变量..?
看来您正在尝试使用 AS2。
您需要将
xmlDocument.toString()
替换为this
,如下所示:Why don't you just assign it to an XML variable..?
Looks like you're trying to use AS2.
You need to replace
xmlDocument.toString()
withthis
like so:我看到您首先发布的问题xml数量有限,
您需要
在最后一个之前使用空格//空格?
其次,我忘记了它叫什么,但在你的第二行中,你以 ? 开头。再次,这应该是您的根节点定义
总而言之,请注意您的间距,并且不要在节点名称中使用问号。
也要尝试逃避,否则如果您使用 cData,稍后会遇到问题
couple things I see with the limited amount of the problem xml you posted
first you need to use spaces
// space before the last ?
Secondly, I forget what it is called but on your second line you are starting with a ? again where this should be your root node definition
To sum it up keep an eye on your spacing and don't use question marks in your node names.
Also try to escape or you will have issues later on if you use cData