[Solved] Best way to read XML data

[Solved] Best way to read XML data
0.0 0



Does anyone know if there is a preferred way to read XML data into Cocos2D-HTML5

Looking at what the internals of the framework does to read the plist and TMX files, I’ve written this code, but it seems strange that there is not a generic way to at least load a xml file into the framework.

Does anyone know if there is some sort of XML loader / parser built into the framework (that I’ve not spotted ).

       var arr=new Array();
        var parser = cc.SAXParser.getInstance();
        var textxml = parser.getList("res/content.xml");
        var xmlDoc;

        // get a reference to the requested corresponding xml file
        if (window.DOMParser)
            var dom_parser = new DOMParser();
            xmlDoc = dom_parser.parseFromString(textxml, "text/xml");
        else // Internet Explorer (untested!)
            xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async = "false";

        var quizElements = x=xmlDoc.getElementsByTagName("quiz");
        for(var i=0;i


Yes, thats the generic XML parser, which is part of DOM JS




I’ll keep using that code :wink: