I Indy Active Member Licensed User Longtime User Mar 4, 2018 #1 Hi, 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: Expand Collapse Copy 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")); Here's the XML response from the WCF; B4X: Expand Collapse Copy <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <ActivityId CorrelationId="8709d988-7118-46e3-a65f-4d81be46993e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">a98d95ae-573d-4636-aadc-738ee383269e</ActivityId> </s:Header> <s:Body> <GetDataResponse xmlns="http://tempuri.org/"> <GetDataResult>You entered: 100</GetDataResult> </GetDataResponse> </s:Body> </s:Envelope> The B4X code I'm using is as follows; B4X: Expand Collapse Copy 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 Have I missed something in my code? Thanks.
Hi, 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: Expand Collapse Copy 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")); Here's the XML response from the WCF; B4X: Expand Collapse Copy <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Header> <ActivityId CorrelationId="8709d988-7118-46e3-a65f-4d81be46993e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">a98d95ae-573d-4636-aadc-738ee383269e</ActivityId> </s:Header> <s:Body> <GetDataResponse xmlns="http://tempuri.org/"> <GetDataResult>You entered: 100</GetDataResult> </GetDataResponse> </s:Body> </s:Envelope> The B4X code I'm using is as follows; B4X: Expand Collapse Copy 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 Have I missed something in my code? Thanks.
Erel B4X founder Staff member Licensed User Longtime User Mar 4, 2018 #2 Indy said: For Each res As Map In root.Get("GetDataResponse") Click to expand... This line is the problem as the compiler doesn't know the stored type. What is the output of Log(root) ? Upvote 0
Indy said: For Each res As Map In root.Get("GetDataResponse") Click to expand... This line is the problem as the compiler doesn't know the stored type. What is the output of Log(root) ?
I Indy Active Member Licensed User Longtime User Mar 4, 2018 #3 Erel said: This line is the problem as the compiler doesn't know the stored type. What is the output of Log(root) ? Click to expand... It says... B4X: Expand Collapse Copy (Map) Not initialized Thanks. Upvote 0
Erel said: This line is the problem as the compiler doesn't know the stored type. What is the output of Log(root) ? Click to expand... It says... B4X: Expand Collapse Copy (Map) Not initialized Thanks.
Erel B4X founder Staff member Licensed User Longtime User Mar 5, 2018 #4 I should have asked: what is the output of Log(ParsedData) ? Worth seeing the web services tutorial. I go over XML parsing in the second example. https://www.b4x.com/etp.html Upvote 0
I should have asked: what is the output of Log(ParsedData) ? Worth seeing the web services tutorial. I go over XML parsing in the second example. https://www.b4x.com/etp.html
I Indy Active Member Licensed User Longtime User Mar 5, 2018 #5 Hi Erel, ParseData contains B4X: Expand Collapse Copy (MyMap) {Envelope={Header={ActivityId={Attributes={CorrelationId=8e40d0fb-0e7b-4d33-92c9-795877a52929}, Text=ed778225-a20f-4c6f-8410-acef76d1217d}}, Body={GetDataResponse={GetDataResult=You entered: 11}}}} 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? Thanks. Upvote 0
Hi Erel, ParseData contains B4X: Expand Collapse Copy (MyMap) {Envelope={Header={ActivityId={Attributes={CorrelationId=8e40d0fb-0e7b-4d33-92c9-795877a52929}, Text=ed778225-a20f-4c6f-8410-acef76d1217d}}, Body={GetDataResponse={GetDataResult=You entered: 11}}}} 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? Thanks.
Erel B4X founder Staff member Licensed User Longtime User Mar 5, 2018 #6 Indy said: 'll be honest with you, what puzzles me is why the error during compilation? Click to expand... This line cannot be compiled as the compiler cannot use an Object in a For Each loop. B4X: Expand Collapse Copy For Each res As Map In root.Get("GetDataResponse") The first step is to format the maps data: To get the "GetDataResult" element: B4X: Expand Collapse Copy 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") Upvote 0
Indy said: 'll be honest with you, what puzzles me is why the error during compilation? Click to expand... This line cannot be compiled as the compiler cannot use an Object in a For Each loop. B4X: Expand Collapse Copy For Each res As Map In root.Get("GetDataResponse") The first step is to format the maps data: To get the "GetDataResult" element: B4X: Expand Collapse Copy 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 Indy Active Member Licensed User Longtime User Mar 5, 2018 #7 Hi Erel, 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) B4X: Expand Collapse Copy (MyMap) {Envelope={Header={ActivityId={Attributes={CorrelationId=06889bd3-b674-4db9-aa51-dcb216e3a85e}, Text=10c59f8d-a4c8-4e0e-afa2-369aa57722e7}}, Body={GetDataListResponse={GetDataListResult={string=[A, B, C]}}}}} I tried the following code but got an error. B4X: Expand Collapse Copy 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: Expand Collapse Copy 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) Can you tell where I've gone wrong? Thanks. Upvote 0
Hi Erel, 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) B4X: Expand Collapse Copy (MyMap) {Envelope={Header={ActivityId={Attributes={CorrelationId=06889bd3-b674-4db9-aa51-dcb216e3a85e}, Text=10c59f8d-a4c8-4e0e-afa2-369aa57722e7}}, Body={GetDataListResponse={GetDataListResult={string=[A, B, C]}}}}} I tried the following code but got an error. B4X: Expand Collapse Copy 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: Expand Collapse Copy 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) Can you tell where I've gone wrong? Thanks.
DonManfred Expert Licensed User Longtime User Mar 5, 2018 #8 try B4X: Expand Collapse Copy dim GetDataListValues As list = GetDataListResult.Get("string") Upvote 0
I Indy Active Member Licensed User Longtime User Mar 5, 2018 #9 Hi DonManfred Worked perfectly! Now I'm able to retreive single and multiple values from the WCF service. Thank you both Erel and DonManfred for your help. Thanks Upvote 0
Hi DonManfred Worked perfectly! Now I'm able to retreive single and multiple values from the WCF service. Thank you both Erel and DonManfred for your help. Thanks