【发布时间】:2015-09-14 08:09:50
【问题描述】:
我正在尝试在 Firefox 插件中使用 JavaScript 构建一些 XML,但遇到了一些问题。
下面是我要找的 XML 格式:
<testing>
<testingOne attr="my_attrib">
<TestingTwo>abc</TestingTwo >
<TestingThree>bbc</TestingThree>
</testingOne >
</testing>
我尝试使用下面的代码。但是,它不起作用。
var XML = document.createElement("div");
var Node = document.createElement("testing");
Node.appendChild( document.createElement("testingOne") );
var a = document.createAttribute("my_attrib");
node.setAttributeNode(a);
Node.appendChild( document.createElement("TestingTwo") );
Node.appendChild( document.createElement("TestingThree") );
XML.appendChild(Node);
alert(XML.innerHTML);
如何像上面的示例一样在 Firefox 插件中使用 JavaScript 创建 XML?
【问题讨论】:
-
您提供的示例“XML 格式”似乎与您使用的代码无关(例如,
testing、testingOne、TestingTwo、TestingThree、@ 987654328@ 以“XML 格式”存在,sub、sub1、abc、bbc在您的代码中不存在)。请更改其中一个以反映您在做什么,或者您说您想要什么。事实上,我们将不得不付出更多的努力来尝试猜测您真正想要什么,而不是仅仅能够查看代码/示例并说这是错误的地方。 -
更改了示例以相互匹配...您现在可以帮帮我吗
-
顺便说一句:如果您希望将您的评论通知特定的人,您需要在评论中包含他们的 ID,并在其前面加上 @。例如,对我来说是@Makyen。如果您将此作为评论中的第一件事,则系统将提供那些已经在该答案/问题上发布 cmets 的人的自动完成建议。您评论的答案/问题的原始海报将始终得到通知。这个meta post 有更多信息。在这种情况下,我将近一年没有看到您的评论。
标签: javascript xml firefox-addon jscript