google / blockly-android

Blockly for Android
Apache License 2.0
672 stars 209 forks source link

Parsing Blockly generated xml in Android #749

Closed praveenb closed 5 years ago

praveenb commented 5 years ago

Generally i use Xstream parser for parsing XML. But XStream parser not working since this XML data has child tag same name as Parent tag. I found this library which converts Blockly xml code to Java objects. But this library fails for Complex Blockly XML code. Please find the attached Blockly generated xml code. blocky_issue.txt

I don't see much help on Blockly parsing.

Please let me know if there is any possible solution or any existing API library for parse Blockly generated XML code.

Thank you.

AnmAtAnm commented 5 years ago

For loading the workspace, use BlocklyController.loadWorkspaceContents(..). There are also simpler helper versions for specific locations: BlocklyActivityHelper.loadWorkspaceFromAppDir(..), BlocklyActivityHelper.loadWorkspaceFromAppDirSafely(..).

Similar methods exist for the toolbox XML.

Under the hood, we use Android's built-in XmlPullParser. See BlocklyXmlHelper.loadBlocksFromXml(..).