
/**
* XmlParser Object
* A javascript class to create an XmlParse.x32 (version 8.5r224) XmlParser object
* 2004-04-06
@author: Andrew Lucking - luckingandrew@yahoo.ca
*/

/* Sample usage:

var xml_file = "http://www.andrewlucking.com/feed/";

// create instance of XmlParser object
var my_xml = new XmlParser();
my_xml.ignoreWhitespace(true);
my_xml.parseFile(xml_file); // call parseFile method

// parsemore loop
var err_str = my_xml.getError();
if (err_str == ""){
    while (!my_xml.doneParsing()){
        err_str = my_xml.getError();
        if ( err_str != "" ){ // an error occured
            aw.Trace(err_str);
            break;
        }
        my_xml.parseMore(); // parsemore
        aw.SyncPoint();
        aw.SyncWait(.1);
    }
} else {
    aw.Trace(err_str)
};

aw.Trace( my_xml.getCount("#child", "1") )

// clean up when finished with the xml object
my_xml.destroy();
*/


/** XmlParser object constructor
*/
function XmlParser(){
    // create xtra instance
    this._id = aw.NewObject("xmlparser");
}

/**
* returns true if done parsing
@return boolean
*/
XmlParser.prototype.doneParsing = function(){
    return aw.CallObject(this._id, "doneParsing");
}
/**
*  returns the name of the attribute specified by an integer
@param  ichild  attribute index
@param  xmlNode comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return string
*/
XmlParser.prototype.getAttributeName = function(iChild, xmlNode){
    return aw.CallObject(this._id, "getAttributeName", iChild, xmlNode);
}
/**
*  returns the value of the attribute specified by an integer
@param  iValue  attribute index
@param  xmlNode comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return string
*/
XmlParser.prototype.getAttributeValueByIndex = function(iValue, xmlNode){
    return aw.CallObject(this._id, "getAttributeValueByIndex", iValue, xmlNode);
}
/**
*  returns the value of the attribute specified by a string
@param  attributeName   string specifying attribute name
@param  xmlNode         comma-delimited string containing the
                        path of node indexes down to the node
                        to be pointed at.
@return string
*/
XmlParser.prototype.getAttributeValueByName = function(attributeName, xmlNode){
    return aw.CallObject(this._id, "getAttributeValueByName", attributeName, xmlNode);
}
/**
*  returns the child node (specified by integer) of the specified XML node
@param iChild
@param xmlNode comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return integer
*/
XmlParser.prototype.getChild = function(iChild, xmlNode){
    return aw.CallObject(this._id, "getChild", iChild, xmlNode);
}
/**
*  returns the number of children or the number of attributes contained in the specified node
@param objectType   #child or #attribute
@param xmlNode      comma-delimited string containing the
                    path of node indexes down to the node
                    to be pointed at.
@return integer
*/
XmlParser.prototype.getCount = function(objectType, xmlNode){
    return aw.CallObject(this._id, "getCount", objectType, xmlNode);
}
/**
*  returns the error string (if any) generated when parsing
@return string
*/
XmlParser.prototype.getError = function(){
    return aw.CallObject(this._id, "getError");
}
/**
*  returns the name of the specified XML node
@param xmlNode  comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return string
*/
XmlParser.prototype.getName = function(xmlNode){
    return aw.CallObject(this._id, "getName", xmlNode);
}
/**
*   returns the text of the specified xml node if the node type is #text
@param xmlNode  comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return string
*/
XmlParser.prototype.getText = function(xmlNode){
    return aw.CallObject(this._id, "getText", xmlNode);
}
/**
*   returns the type( #element or #text ) of the specified XML node
@param xmlNode  comma-delimited string containing the
                path of node indexes down to the node
                to be pointed at.
@return property (#element or #text)
*/
XmlParser.prototype.getType = function(xmlNode){
    return aw.CallObject(this._id, "getType", xmlNode);
}
/**
*   toggles whether to ignore whitespace
@param bool true to ignore whitespace
*/
XmlParser.prototype.ignoreWhitespace = function(bool){
    return aw.CallObject(this._id, "ignoreWhitespace", bool);
}
/**
*  make a lingo (Authorware script) list based on the XML document
@return authorware list
*/
XmlParser.prototype.makeList = function(){
    return aw.CallObject(this._id, "makeList");
}
/**
*   begins the process of parsing the specified url. Check
    doneParsing to determine if the parsing has completed.
    Use parseMore to force the xtra to read and parse more
    data.
    Note: the XMLParser xtra requires idle time to process
    the file. Don't use parseMore within a repeat loop.
@param file file to be parsed
*/
XmlParser.prototype.parseFile = function(file){
    return aw.CallObject(this._id, "parseFile", file);
}
/**
* parses more of an XML document
*/
XmlParser.prototype.parseMore = function(){
    return aw.CallObject(this._id, "parseMore");
}
/**
* parses the buffer (xml string passed)
@param data string of xml data to be parsed
*/
XmlParser.prototype.parseString = function(data){
    aw.CallObject(this._id, "parseString", data);
}
/**
*   deletes instance of xmlparser xtra
    should be called before deleting the XmlParser instance
*/
XmlParser.prototype.destroy = function(){
    return aw.DeleteObject(this._id);
}


