为什么动作脚本只将一段字符串分配给变量?

发布于 2024-11-09 10:49:26 字数 656 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晚雾 2024-11-16 10:49:26

为什么不把它赋给一个 XML 变量..?

var xml:XML =
<shop>
    <item id="10">
        <price>20</price>
    </item>
</shop>;

看来您正在尝试使用 AS2。

您需要将 xmlDocument.toString() 替换为 this,如下所示:

var xml:XML = new XML();

xml.onLoad = function(success:Boolean):Void
{
    if(success)
    {
        trace(this);
    }
}

xml.load("file.xml");

Why don't you just assign it to an XML variable..?

var xml:XML =
<shop>
    <item id="10">
        <price>20</price>
    </item>
</shop>;

Looks like you're trying to use AS2.

You need to replace xmlDocument.toString() with this like so:

var xml:XML = new XML();

xml.onLoad = function(success:Boolean):Void
{
    if(success)
    {
        trace(this);
    }
}

xml.load("file.xml");
孤凫 2024-11-16 10:49:26

我看到您首先发布的问题xml数量有限,

您需要

在最后一个之前使用空格//空格?

var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8"?>';
//should be 
var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8" ?>';

其次,我忘记了它叫什么,但在你的第二行中,你以 ? 开头。再次,这应该是您的根节点定义

// this is bad
    xmlDoc += '<?dctm xml_app=" ......
// should be assuming dctm is your node name
    xmlDoc += '<dctm xml_app=" ......

总而言之,请注意您的间距,并且不要在节点名称中使用问号。

也要尝试逃避,否则如果您使用 cData,稍后会遇到问题

var xmlDoc:String = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

couple things I see with the limited amount of the problem xml you posted

first you need to use spaces

// space before the last ?

var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8"?>';
//should be 
var xmlDoc:String = '<?xml version="1.0" encoding="UTF-8" ?>';

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

// this is bad
    xmlDoc += '<?dctm xml_app=" ......
// should be assuming dctm is your node name
    xmlDoc += '<dctm xml_app=" ......

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

var xmlDoc:String = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文