Here's a handy little class that might help you with what you're trying to do... It'll let you dot down through your xml...

note: the warning @ the top of the class is a reminder to use the flex built int XMLUtil's static createXML func to transform the xml string you get back from the webservice into an XML Object




/****************************************************************************
!!!!!!!!!!!!!!!!    WARNING: YOU MUST RUN THE input_xml THROUGH XMLUtil.createXML( :string) !!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!    YOU NEED THE OBJECT IT RETURNS... NO OTHER FORMAT WILL WORK                !!!!!!!!!!!!!!!!!!!!!!!!!!
   
    Description: Converts the XML to an object needed for the modules   
    you can access your XML data in an object like this:
        xmlObj.addressBook.person[0].name;   
    if you want to access attributes, you can do it like this:
        xmlObj.addressBook.person[0].attributes.nickname;
    and vice versa
    Version: 1.0
    Author: Michelangelo Capraro
    Email:
    Created: May/10/04
    Modified By: Clint Modien
****************************************************************************/

class core.utils.XMLHelper
{   

    public static function XML2Object(input_xml:XMLNode):Object
    {       
        // make an empty object to attach properties and other objects to
        var returnObj = new Object();
        var tempObj = new Object();
   
        // loop throught the child nodes of the returned xml...
        for (var nodeIndex = 0; nodeIndex < input_xml.childNodes.length; nodeIndex++) {
            var currentNode = input_xml.childNodes[nodeIndex];
           
            // for text nodes.....
            if (!(currentNode.firstChild.nodeValue == null && currentNode.hasChildNodes())) {
                // anything thats not another nest of nodes, just make properties from them
                // creating a String object lets us add properties to it later
                var tempNode = new String(currentNode.firstChild.nodeValue);
                           
                if (returnObj[currentNode.nodeName] == null) {
                    returnObj[currentNode.nodeName] = tempNode;
                   
                    // this is used for attaching attributes later
                    tempObj = returnObj[currentNode.nodeName];
                } else {
                    // make an array if it doesn't exist already
                    if (returnObj[currentNode.nodeName][0] == null) {
                        var tempObj = returnObj[currentNode.nodeName];
                        returnObj[currentNode.nodeName] = new Array();
                        returnObj[currentNode.nodeName][0] = tempObj;
                    }
                    returnObj[currentNode.nodeName].push(tempNode);
                   
                    // this is used for attaching attributes later
                    tempObj = returnObj[currentNode.nodeName][returnObj[currentNode.nodeName].length - 1];
                }   
   
            } else {
   
                // this is another nested object....
                // if an object of this name doesnt exists...
                if (returnObj[currentNode.nodeName] == null) {
                    returnObj[currentNode.nodeName] = XML2Object(currentNode);
                   
                    // this is used for attaching attributes later
                    tempObj = returnObj[currentNode.nodeName];
                } else {
                    // make an array if it doesn't exist already
                    if (returnObj[currentNode.nodeName][0] == null) {
                        var tempObj = returnObj[currentNode.nodeName];
                        returnObj[currentNode.nodeName] = new Array();
                        returnObj[currentNode.nodeName][0] = tempObj;
                    }
                    returnObj[currentNode.nodeName].push(XML2Object(currentNode));
                   
                    // this is used for attaching attributes later
                    tempObj = returnObj[currentNode.nodeName][returnObj[currentNode.nodeName].length - 1];
                }   
   
            }
           
            tempObj.attributes = new Object();
           
            var attributeCounter = 0;
            for (var a in currentNode.attributes) {
                attributeCounter++
                tempObj.attributes[a] = currentNode.attributes[a];
            }
            if (attributeCounter == 0) {
                tempObj.attributes = null;
            }
               
        }
   
        // return the new object
        return returnObj;
   
    }
}



On 6/17/05, Tony Rozario <[EMAIL PROTECTED]> wrote:
Hi,
  If i change the result format from a web service as XML & then do data binding of the result to a data grid, i dont get the expected results.
  I get numerous column headers which i cant read, some of them are getChildNode, NextChild,.... something like that.
 The webservice result what i get when i see from the network monitor is different from that of the result which i get when i test the web service from a native server. i.e, when i check the network monitor,it gives only the first 2 nodes & its not getting the other nodes.
Can anyone explain to  me the reason behind these odd behaviours,
tony

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com


Yahoo! Groups Links




Yahoo! Groups Links

Reply via email to