I'm trying to use Xml2Map class to get values from XML that is passed back from a WCF. I followed the example in the first post to loop through the data from the XML string but, changed the XML references as per my output, however I get a compilation error as follows;
B4X:
Compiling generated Java code. Error
B4A line: 105
For Each res As Map In root.Get(\
javac 1.8.0_131
src\b4a\example\main.java:485: error: incompatible types: Object cannot be converted to IterableList
group26 = _root.Get((Object)("GetDataResponse"));
Dim xm As Xml2Map
xm.Initialize
ParsedData = xm.Parse(strXMLResponse)
Dim root As Map = ParsedData.Get("Body")
For Each res As Map In root.Get("GetDataResponse")
Next
I'll be honest with you, what puzzles me is why the error during compilation? Surely it can't know what XML tags to expect until the app actually runs. The only thing I can think of is, all the examples for this load an XML file whereas I want to pass in XML. Do you think the complier loads in the file before and then validates the tags at compilation time?
This line cannot be compiled as the compiler cannot use an Object in a For Each loop.
B4X:
For Each res As Map In root.Get("GetDataResponse")
The first step is to format the maps data:
To get the "GetDataResult" element:
B4X:
Dim Envelope As Map = ParsedData.Get("Envelope")
Dim Body As Map = Envelope.Get("Body")
Dim GetDataResponse As Map = Body.Get("GetDataResponse")
Dim result As String = GetDataResponse.Get("GetDataResult")
I see where I was going wrong. I have used your code and it works. However, what I've now done is to try and extend that to loop through a collection of data. So, for example I now have the following data (from ParseData)
Dim Envelope As Map = ParsedData.Get("Envelope")
Dim Body As Map = Envelope.Get("Body")
Dim GetDataListResponse As Map = Body.Get("GetDataListResponse")
Dim GetDataListResult As Map = GetDataListResponse.Get("GetDataListResult")
Dim GetDataListValues As Map = GetDataListResult.Get("string")
For Each res As String In GetDataListValues.Values
Msgbox(res,"")
Next
B4X:
main$ResumableSub_Button1_Clickresume (java line: 525)
java.lang.ClassCastException: java.util.ArrayList cannot be cast to anywheresoftware.b4a.objects.collections.Map$MyMap
at b4a.example.main$ResumableSub_Button1_Click.resume(main.java:525)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:240)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
at anywheresoftware.b4a.keywords.Common$11.run(Common.java:1135)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5546)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)