smart-fun / XmlToJson

Android Library for converting XML to JSON and JSON to XML
Apache License 2.0
558 stars 112 forks source link

Truncated conversion xml file #15

Closed Angelk90 closed 6 years ago

Angelk90 commented 6 years ago

@smart-fun : Hi, congratulations on the module. I have to convert files that weigh over 200 KB. At the time of the conversion when I print the result on the Android console, I notice that not everything is converted, but stops at one side. It converts less than 1/41 of what it should convert. Estimating more or less 4.5-4.9 KB are converted. What can I do? Does the module support converting files of this size?

smart-fun commented 6 years ago

Hello Angelk90 and thanks for using XmlToJson!

The size of the String when you log to the console is truncated by Android, so it does not mean that the conversion has stopped. You should log the size of the String instead, like Log.i(TAG, convertedString.length()); so that you'll see if this is only a console issue.

200KB is quite big for a String, I never tried to convert so big texts, but I don't see any reason why it could fail. If you confirm that the length is still 5KB for a source of 200K, please send me the file so that I can give it a try.

Arnaud.

Angelk90 commented 6 years ago

@smart-fun : It seems that it works correctly, I do not understand why if I printed the .xml file, it prints everything, on several lines but everything. Instead if I print this truncates it, perhaps it considers it as a single string and can not divide it into several parts.

P.Š. I would not go off the subject, but I wanted to ask something, if not I create a new issue.

I have the following file: http://jsoneditoronline.org/?id=6449e6640a8574d4d21880793872c8f8

I did not understand how I can navigate on it. So I have the string "str", which contains the .xml file as a string. How can I make sure to create a variable that contains only the value of the array item. Then you can cycle the following array, to be able to print the attributes it contains?

smart-fun commented 6 years ago

Hi,

you should not convert it to String if you want to navigate the Json, you should keep the JSONObject. For exampe:

JSONObject jsonObject = xmlToJson.toJson();

Then you can parse the Json with methods like JSONArray myArray = jsonObject.optJSONArray("yourArrayName"); or JSONObject otherObject = jsonObject.optJSONObject("yourObjectName") or String value = jsonObject.optString("attributeName")

see documentation: https://developer.android.com/reference/org/json/JSONObject.html

I hope that this is what you were expected!

Arnaud.