主に Web サイトやその他のアプリケーション向けの xml パーサーの書き方について、すでに多くの質問が寄せられています。
次のような有用であることが証明されている他のチュートリアルもあります。
http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery
ただし、ファイル形式 sbml (システム生物学マークアップ言語) のパーサーを作成しようとしています。
仕様 - http://sbml.org/Documents/Specifications
私はパーサーをハードコーディングしようとしてきましたが、私が持っているケースでは機能しますが、すべてのセクションでは機能しません。
$(document).ready(function()
{
//alert("In function");
$.ajax({
type: "GET",
url: "sbml.xml",
dataType: "xml",
success: parseXml
});
});
function parseXml(xml) {
//alert("Xml loaded");
$("#output").append("Output loaded <br />" );
$(xml).find("model").each(function() {
$("#output").append("Found model <br />" );
//alert("Found model");
//alert($(this).attr("id"));
$(xml).find("listOfCompartments").each(function() {
//alert("Found list of compartments");
$("#output").append("List of Compartments found <br />" );
$.each($(this).children(), function() {
var id = $(this).attr("id");
var size = $(this).attr("size");
//alert("Id: " + id + ", Size: " + size);
$("#output").append("Compartment <br />" );
$("#output").append("Id: " + id + ", Size: " + size + "<br />");
});
});
});
}
仕様は非常に大きく (8 ページ)、変更される傾向があるため、そのような場合のパーサーを作成するためのより良い方法はありますか?
すべてをハードコーディングするのではなく、可能なすべてのノードの配列を作成してループスルーすることは可能でしょうか。これはより効率的でしょうか?