Share My Creation [B4x] MineXML Auto create Class and b4xlib

A B4j tool that started out as an XML viewer based on the XML2Map lib, but quickly changed into a parser and Class and library creator. I wanted to improve my knowledge of XML files, and this is the result. The resulting code and libraries should be cross platform, Tested on B4j and B4a and should work on B4i.

What it does:

  • Extract XML keys from an XML file
  • Merge multiple files to extract keys
  • Allows adding friendly names for the keys
  • Creates a class to access the selected keys from an XML file using the assigned friendly names (or tags from the XML if not defined)
  • Export the class as a b4xlib
  • Warn if a key is present in an XML file that is not recognised. (Optional)

There is also a companion app to help check that the library is working correctly.

upload_2019-11-26_20-18-17.png


Open an XML file using the OpenXML button, the file menu options are for loading and saving the project data. Hopefully it will parse the file and display the keys and data.

Not all XML files contain all keys that the data set can contain, so you can merge additional files to try to catch them all. Use the MergeXML file to add keys from additional files. Once files are merged, the data becomes a mixture of the two files, but it serves as a test to check what is there.

Add friendly names for keys that are not going to be easily identifiable when you are retrieving the data in your program. I have tried to replace characters from the keys that will cause problems with B4x variable names, but if you add friendly names, that problem goes away.

Select the keys that you want to include in your class and decide if you want to be warned if an unidentified key is found while you are using the library. Click the Create Class Code button.

upload_2019-11-26_20-45-49.png


The generated class will be displayed using Erel's B4xSimpleCodeHighlighter, you can copy this to the clipboard to paste into a new class in your program, requires the XML2Map library, or you can create a b4xlib containing the class. Save this in your b4xlib directory so that it is accessible to the testing app. If you leave the module name as MineXML you can use it directly with the provided test program without making any changes to it. You can name the b4xlib anything you want (just don't overwrite another library).

Download the test program, don't run it yet as there is no default library. You will see errors in the logs until you select your created library in the libraries tab or create a new class in the test project called MineXML and copy the generated code in there, if you asked to include the warning for unrecognised keys you will need to change the MineXML.Initialize call to the one that is currently commented in the test program.

upload_2019-11-26_20-46-15.png


Copy the Test Code from the TestCode tab of MineXML to the Testing program removing any already there. and run the app. There are two levels of tests, a Short test and a Normal test, this is to do with the amount of data displayed rather than time. The Normal tests are commented when copied.

upload_2019-11-26_20-47-25.png



I have tested quite a few files small and not so small, if you find problems with any (and I expect you will), let me know and I'll try to find out why and fix the program if needs be.

This is experimental for me, so please test it carefully before using in production and report any bugs. And as always, if you try it, let me know how you get on with it.

I've tested it on B4j and B4a, if anyone tries it on B4i, please let me know if it works, I don't see any reason why it shouldn't

Dependencies:

MineXML depends on: XML2Map, KeyValueStore, RandomAccessFile, BCTextEngine, XUI Views
MineXMLTesting depends on XML2Map, KeyValueStore and your generated library, or code pasted into a class.

All code is in the project files attached.

Update v1.1
  • Faster parsing and handling of larger files
  • Shows count of data items for large lists
  • Better validation of entered Variable and Module names
  • Added B4xTable to display data in a better format and export to csv
  • Improved merging data storage
10
 

Attachments

  • MineXMLTesting.zip
    4.3 KB · Views: 304
  • MineXML1-1.zip
    83.4 KB · Views: 308
Last edited:
Top