Using cc.SAXParser on Android and iOS

Hi, I am developing an app using the JS bindings, I test with the cocos2d-html5, all works great, at some point I use the cc.SAXParser to parse an XML, all works ok on html5.

now I want to setup the Android project,all works great, except when I call the parser, I first got the message:

JS: assets/src/MyMainClass.js:38:TypeError: cc.SAXParser is undefined

I then added the CCSAXParser.js inside my assets/src folder, and added to the cocos2d-jsb.js, now I get the error:

JS: assets/src/CCSAXParser.js:41:ReferenceError: window is not defined

I’m confuse, how should we use this class if we want to build for Android or iOS?

Thanks for the help.

SAXParser was not binded to JSB.

You should convert all your xml to JSON, as it is a superior format when dealing with javascript, as it is natively supported, faster, and use less space

Great! So if I use JSON.parse that would be supported on all html5 and Android/iOS right?

Thanks again.

YES, JSON.parse is natively supported by SpiderMonkey

1 Like