Help!!! How to read local xml files?

Help!!! How to read local xml files?
0.0 0

#1

I use XMLHttpRequest to read local xml file in cocos2d-html5.But it can not read by the same way in cocos2d-x JSB.How to read local xml files in cocos2d-x JSB


#2

There’re no xml parser in cocos2d-x JSB right now. I advise you use JSON format instead.


#3

James Chen wrote:

There’re no xml parser in cocos2d-x JSB right now. I advise you use JSON format instead.

Can I use plist format?


#4

#5

James Chen wrote:

http://www.cocos2d-x.org/boards/20/topics/28538

Which format can parser in cocos2d-x JSB right now,And how to parser them? I perfer to use cocos2d-x JSB api rather than I bind it by myself.


#6

Javascript supports JSON.parse() originally.


#7

James Chen wrote:

Javascript supports JSON.parse() originally.

Thanks a lot


#8

James Chen wrote:

Javascript supports JSON.parse() originally.

By the way,How to read file content that supported both in cocos2d-HTML5 and cocos2d-x JSB?


#9

cc.FileUtils.getInstance().getStringFromFile(filename);


#10

James Chen wrote:

cc.FileUtils.getInstance().getStringFromFile(filename);

Is it need to call other method before call this method?I call this method but get void by return.


#11

Not needs other method.


#12

James Chen wrote:

Not needs other method.

Why I get void by return?I try to read some ccbi file which can read by cc.BuilderReader.load.But it still get void by return.


#13

Platform? Engine version?
Please, please don’t just say the problem, please provide the details.


#14

Platform? Engine version?
Please, please don’t just say the problem, please provide the details.


#15

James Chen wrote:

Platform? Engine version?
Please, please don’t just say the problem, please provide the details.

Sorry.Plaform is cocos2d-HTML5 2.1.4


#16

:frowning: , so you don’t use cocos2d-x JSB?
If so please post your feedback here(http://www.cocos2d-x.org/projects/cocos2d-x/boards/19)
This sub forum is just for cocos2d-x JSB.


#17

James Chen wrote:

:frowning: , so you don’t use cocos2d-x JSB?
If so please post your feedback here(http://www.cocos2d-x.org/projects/cocos2d-x/boards/19)
This sub forum is just for cocos2d-x JSB.

I develop in cocos2d-HTML5 and also run it in cocos2d-x JSB.So I want to know the way which can supported both in HTML5 and JSB


#18

OK. I noticed that you read .ccbi format from file. .ccbi is binary format. So getStringFromFile will not work.
Instead, you could use cc.FileUtils.getInstance.getByteArrayFromFile;.


#19

James Chen wrote:

OK. I noticed that you read .ccbi format from file. .ccbi is binary format. So getStringFromFile will not work.
Instead, you could use cc.FileUtils.getInstance.getByteArrayFromFile;.

Actually,I just want to read json file both in cocos2d-x JSB and cocos2d-HTML5


#20

iOS, Android?
Could you provide a demo to reproduce it. Otherwise, I have no ideas about that.