【发布时间】:2013-04-11 09:00:25
【问题描述】:
我希望解析这样的 XML 文件
<class>
<subject>
<knowledgeLevel> 1 </knowledgeLevel>
<subjectName> Try1 </subjectName>
<theory>
<tutorial> Quickly Explain Try1 </tutorial>
<full> Largely Explain Try1 </full>
</theory>
<example>
<id> 1 </id>
<code> some code </code>
<level> easy </level>
</example>
<example>
<id> 2 </id>
<code> some code </code>
<level> hard </level>
</example>
</subject>
</class>
考虑到最后文件中会出现多个主题,如何让理论和示例的子孩子用Javascript编写HTML表格?
【问题讨论】:
-
在循环通过 XML 解析器查看我的答案?[1] [1]:stackoverflow.com/a/15612898/1058406
-
@Janinho67 查看$.parseXML(),它会将其解析为类似数组的结构,然后将字符串读写并连接在一起,直到您可以形成一个html
table。 -
@Janinho67:作为纯文本字符串的 XML 文件是什么格式的?如果它是通过 XHR 加载的,它应该已经是一个 DOM 文档(不需要解析它,只需遍历它)
-
xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","subjects.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML;
标签: javascript html xml