Javascript xml未提供适当的节点
您好,提前谢谢 我已经在加载XML数据并解析到assoc数组的问题上耽搁了几天。我最终决定将XML配置数据直接嵌入启动HTML5文档的标题中 下面我已经包括了整个文件。当通过parseFromString()加载数据时,我得到了一些节点,但从其他节点得到了解析错误,还有一些甚至没有出现。我已经搞砸了好几天了,我不明白为什么会出现解析错误Javascript xml未提供适当的节点,javascript,xml,formatting,nodes,Javascript,Xml,Formatting,Nodes,您好,提前谢谢 我已经在加载XML数据并解析到assoc数组的问题上耽搁了几天。我最终决定将XML配置数据直接嵌入启动HTML5文档的标题中 下面我已经包括了整个文件。当通过parseFromString()加载数据时,我得到了一些节点,但从其他节点得到了解析错误,还有一些甚至没有出现。我已经搞砸了好几天了,我不明白为什么会出现解析错误 <!-- I2TM Game Engine [Developer] --> <!DOCTYPE HTML> <html lang=
<!-- I2TM Game Engine [Developer] -->
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>I2TM: Example Template</title>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<script id="resources" type="text/xmldata">
<resources name="Template" version="0.1" publisher="I2TM Software" copyright="2012-2013">
<credits>
<credit id="0" name="Andrew Donelson" url="http://www.i2tmsoftware.com" desc="Author" />
<credit id="1" name="Playcraft Labs" url="http://www.playcraftlabs.com" desc="I2TM Engine forked from PlaycraftJS v0.5.6" />
<credit id="2" name="SoundManager2" url="http://www.schillmania.com/projects/soundmanager2/" desc="Used in I2TM Engine as primary Sound API" />
<credit id="3" name="James Padolsey" url="https://github.com/padolsey/string/blob/master/string.js" desc="Used in I2TM Engine extended String API" />
<credit id="4" name="Alexandru Marasteanu" url="http://www.diveintojavascript.com/projects/javascript-sprintf" desc="Used in I2TM Engine to add sprintf capability" />
</credits>
<languages>
<language name="english" from="english" to="english" />
<language name="spanish" from="english" to="spanish" />
<language name="german" from="english" to="german" />
</languages>
<sounds>
<sound name="i2tm" ogg="true" mp3="true" channels="1" file="sounds/i2tm" />
</sounds>
<images>
<image name="publisher" file="images/publisher.png" />
<image name="touchpad" file="images/touchpad_buttons.png" />
<image name="title" file="images/title.png" />
<image name="starport" file="images/starport.png" />
</images>
</resources>
</script>
<!--[if lt IE 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
</head>
<body>
<script type="text/javascript" src="../playcraftengine/playcraftjs/lib/playcraft.js"></script>
<!-- Engine creates game elements and restores upon friendly exit. -->
<div id="pcGameDiv">
<div>
<!-- Development -->
<a class="caption" href="javascript:pc.start('js/', ['game.main.js','touch.main.js','game.resources.js','factory.entity.js','factory.sound.js','scene.publisher.js','scene.mainmenu.js','scene.touchpad.js','scene.game.js','system.touchpad.js'],'../playcraftengine/playcraftjs/lib/');">Play Now</a>
<!-- Production
<a class="caption" href="javascript:pc.start('js/', ['game.min.js']);">Play Now</a>
-->
</div>
<div><strong>Game Title</strong><p>replaces this text with the description of your game here</p></div>
<div><strong>Help</strong><p>Replace this with how to play or other helpful information</p></div>
</div>
</body>
</html>
I2TM:示例模板
游戏标题将此文本替换为此处的游戏描述
帮助将其替换为如何播放或其他有用信息
[用于获取和解析的代码]
loadResources:function()
{
函数xml_到_数组(xml,标记)
{
var data=xml.getElementsByTagName(标记);
var res={};
如果(数据)
{
对于(i=0;i),您的XML无效,错误消息应该会直接指向问题:
desc="Author & Publisher"
请参见未替换的符号AND?应为Author&;Publisher
作为记录,这是我从webkit上的parseFromString
中获得的(序列化)输出,它直接指向问题所在(第4行第37列--xmlParseEntityRef):
此页面包含以下错误:
第4行第37列出错:xmlParseEntityRef:无名称
下面是第一个错误之前的页面呈现。
playcraft.js
是404,无论如何,问题应该包括一个自包含的示例,而不是指向外部代码的链接。(在问题中包括XML。)我这样做是因为我无法将HTML文档显示为代码而不是HTML。我尝试了pre、code pre和code。至于playcraft,它不需要。只需使用显示的代码即可。只需将名称:function()更改为function name().我更担心的是,为什么我的节点一旦读入DOM就会出错。向左缩进四个空格,或者只使用{}
按钮。如果你点击?
按钮,工具栏会有很多帮助。天哪!我在一个nOOb bug上浪费了好几天。这是90年代初的标准流程。我觉得自己太笨了。谢谢。所有节点都出现了。谢谢弗朗西斯。工作得很好。解决了。
desc="Author & Publisher"
<resources name="Template" version="0.1" publisher="I2TM Software" copyright="2012-2013">
<parsererror xmlns="http://www.w3.org/1999/xhtml" style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em; margin: 1em; background-color: #fdd; color: black">
<h3>This page contains the following errors:</h3>
<div style="font-family:monospace;font-size:12px">error on line 4 at column 37: xmlParseEntityRef: no name</div>
<h3>Below is a rendering of the page up to the first error.</h3>
</parsererror>
<credits></credits>
</resources>