Archive for janvier 4th, 2010
Version 0.1
by admin on jan.04, 2010, under Non classé
There is the 0.1 version.
//XMLElement constructor function XMLElement(parent, file){ // The parent of the XMLELement this.parent = parent; // The file of the XMLELement this.file = file; // The XML document this.xmlDoc = null; // The ChildNodes of The XML Elements this.childNodes = null; // The name of the XMLELement this.name = null; // The content of the XMLElement this.content = null; // The file has to be loaded for the first XMLElement only if(file != null){ try{ this.xmlDoc = document.implementation.createDocument("","",null); this.xmlDoc.async = false; this.xmlDoc.load(file); } catch(e){ alert(e.message); return; } } //This function has for goal to avoïd the text element in child Nodes. Only Node Element are managed function getFilteredChildNodes(childNodes){ var result = new Array(); for(var i = 0; i < childNodes.length; i ++){ if(childNodes[i].nodeType == 1 ){ result[i] = childNodes[i]; } } return result; }; //This function creates is used by methods getChild(), and getChildren() function createXMLElement(childNode){ var result = new XMLElement(this, this.file); result.xmlDoc = this.xmlDoc; // On creation ChildNodes are always filtered result.childNodes = getFilteredChildNodes(childNode.childNodes); result.name = childNode.nodeName; return result; }; //This function has for goal to check that the given index is correct for a childNodeArray function checkIndexValidity(childNodes, index){ if(index >= childNodes.length || index < 0){ throw "The given index is not valid and is not between 0 and childNodes.length"; } }; //Check if the childNodes attribute is null, if it is null it means that the current element is the root element. // So the array must be filtered. function getFilteredChildNodes(childNodes, xmlDoc){ if(childNodes == null){ return getFilteredChildNodes(xmlDoc.childNodes); }else{ return childNodes; } }; //This method must return the number of children of the element this.getChildCount = function getChildCount(){ return getFilteredChildNodes(this.childNodes, this.xmlDoc).length; }; //This method must return the child at the given index. this.getChild = function getChild(index){ var child = getFilteredChildNodes(this.childNodes, this.xmlDoc)[index]; var result = createXMLElement(child); return result; }; // Returns all of the children as an XMLElement array this.getChildren = function getChildren(){ var result = new Array(); var childNodesArray = getFilteredChildNodes(this.childNodes, this.xmlDoc); for(var i = 0; i < childNodesArray.length; i ++){ var child = createXMLElement(childNodesArray[i]); result.push(child); } return result; } // Returns the content of the element this.getContent = function getContent(){ } }; function setup(){ var xmlElement = new XMLElement(this, "sites.xml"); var childCount = xmlElement.getChildCount(); var childName = xmlElement.getChild(0).getChild(1).name; var children = xmlElement.getChild(0).getChildren(); var stop; }; setup(); ///////////////////************************************************************************* function Personne(){ this.call = function call(){ alert("yo"); }; }; var personne = new Personne(); personne.call(); ///////////////////*************************************************************************