comete_blog

by admin on jan.03, 2010, under Non classé

There is the new version of the xmlElement. This time oriented object javascript has been really used.

There are actually 3 methods that miss :


//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 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];
}
if(childNodes[i].nodeType == 3 ){
this.content = childNodes[i];
}
}
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 result = new XMLElement(this, file);
var kidNode = getFilteredChildNodes(this.childNodes, this.xmlDoc)[index];
result.xmlDoc = this.xmlDoc;
// On creation ChildNodes are always filtered
result.childNodes = getFilteredChildNodes(kidNode.childNodes);
result.name = kidNode.nodeName;
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 = new XMLElement(this, file);
child.xmlDoc = this.xmlDoc;
// On creation ChildNodes are always filtered
child.childNodes = getFilteredChildNodes(childNodesArray[i].childNodes);
child.name = childNodesArray[i].nodeName;
result.push(child);
}
return result;
}
// Returns the content of the element
this.getContent = function getContent(){

}
};
this.setup = 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();
///////////////////*************************************************************************

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

    Archives

    All entries, chronologically...