yo3ggx Active Member Licensed User Longtime User Dec 12, 2023 #1 Hello, Let's consider the following simple xml file as xmlstring. B4X: Copy <main> <device> <memory> <param1>123456</param1> <param2>654321</param2> </memory> <memory> <param1>45678</param1> <param2>87654</param2> </memory> </device> </main> I'm using the following code to extract memories parameters in a list. B4X: Copy Dim xm as XML2MAP xm.Initialize Dim Parsed as Map = xm.Parse(xmlstring) Dim mapdev as Map = Parsed.get("device") Dim lstmems as List = mapdev.get("memory") So I get in lstmems a list of maps with 2 maps. Unfortunately sometimes can be a single memory definition in the xml file, so the returned value from Dim lstmems as List = mapdev.get("memory") is a map instead of a list. There is a better way to deal with this than using Try .. Catch to capture the error and then to get a map instead of a list? Thank you.
Hello, Let's consider the following simple xml file as xmlstring. B4X: Copy <main> <device> <memory> <param1>123456</param1> <param2>654321</param2> </memory> <memory> <param1>45678</param1> <param2>87654</param2> </memory> </device> </main> I'm using the following code to extract memories parameters in a list. B4X: Copy Dim xm as XML2MAP xm.Initialize Dim Parsed as Map = xm.Parse(xmlstring) Dim mapdev as Map = Parsed.get("device") Dim lstmems as List = mapdev.get("memory") So I get in lstmems a list of maps with 2 maps. Unfortunately sometimes can be a single memory definition in the xml file, so the returned value from Dim lstmems as List = mapdev.get("memory") is a map instead of a list. There is a better way to deal with this than using Try .. Catch to capture the error and then to get a map instead of a list? Thank you.
Erel B4X founder Staff member Licensed User Longtime User Dec 13, 2023 #2 Check the "common pitfalls" for a solution: https://www.b4x.com/android/forum/threads/b4x-xml2map-simple-way-to-parse-xml-documents.74848/ Upvote 0
Check the "common pitfalls" for a solution: https://www.b4x.com/android/forum/threads/b4x-xml2map-simple-way-to-parse-xml-documents.74848/
yo3ggx Active Member Licensed User Longtime User Dec 13, 2023 #3 How did I miss it when I looked in that thread.... Upvote 0