所以我得到了三个级别的 XML:
app.xml 包括 4 个类别(XML 文件)。每个类别包括许多条目。
包含部分现在使用 Xinclude 完成。
我的脚本现在运行一个 Ajax 函数来获取第一个 xml,app.xml,但不会看透 Xinclude。为了澄清,我收到警报“是”和“应用程序”,但不是“猫”。在 console.dir xml 中,我看到了 xi:include,但没有看到文件中的内容。
我需要以某种方式解析它吗?我的 Xinclude 不起作用,还是我可以以更好的方式进行包含?
脚本.js
$.ajax({
type: "GET",
url: "xml/app.xml",
dataType: "xml",
success: function(xml) {
alert('yes');
$(xml).find('app').each(function(){
alert('app');
var test = $(this);
console.dirxml(xml);
$(this).find('category').each(function(){
alert('cat');
});
});
},
error: function() {
alert("The XML File could not be processed correctly.");
}
});
应用程序.xml
<?xml version="1.0" encoding="UTF-8"?>
<app xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include href="cat1.xml" parse="xml"/>
<xi:include href="cat2.xml" parse="xml"/>
<xi:include href="cat3.xml" parse="xml"/>
<xi:include href="cat4.xml" parse="xml"/>
</app>
类别示例 - XML
<?xml version="1.0" encoding="UTF-8"?>
<category xmlns:xi="http://www.w3.org/2001/XInclude">
<title>Title</title>
<introtext>Introtext introtext introtext introtext</introtext>
<xi:include href="cat1/entry.xml"/>
</category>
条目示例 - XML
<?xml version="1.0" encoding="UTF-8"?>
<entry>
<rubrik>Entry title</rubrik>
<text>Text text text</text>
<bild>pic_name</bild>
</entry>