codice:
function ReadXmlFile() {
var m_scene = [];
}
ReadXmlFile.prototype = {
load: function (render) {
m_scene = new Array();
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
xmlDoc.load("test.xml");
readXMLFile(render);
},
GetScene: function () {
return m_scene;
}
}
function readXMLFile(render) {
var path = "/Root/Batches/Batch/Positions";
var nodes1 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/Normals";
nodes2 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/UVFront";
nodes3 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/UVBack";
nodes4 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/TextureFront";
nodes5 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/TextureBack";
nodes6 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/ColorFront";
nodes7 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Batches/Batch/ColorBack";
nodes8 = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
path = "/Root/Textures";
var nodesTextures = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
var strTextures = nodesTextures.snapshotItem(0).textContent.split(";");
for (var k = 0; k < strTextures.length; k++) {
render.GetTextureManager().initTexture("TexturesModel/" + strTextures[k]);
}
var path = "/Root/BVV";
var nodesPos = xmlDoc.evaluate(path, xmlDoc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
if (nodesPos.snapshotItem(0).textContent != "") {
var str = nodesPos.snapshotItem(0).textContent.split(" ");
m_Pos[0] = parseFloat(str[0]);
m_Pos[1] = parseFloat(str[1]);
m_Pos[2] = parseFloat(str[2]);
}
//ecc... per gli altri dati
alla fine prendo snapshotItem(0) o n e passo una serie di dati 1 2 3 4 5 separati da " " alla classe che crea i miei oggetti e termina il parsing oppure termino direttamente il parsing nell oggetto leggendo le mie variabili come per BVV(sta per bounding volume).