07-03-2015 02:56 AM - edited 07-03-2015 03:02 AM
Maybe a good idea to start a LibXML Example and FAQ Thread !.
I came from EasyXML, which I used over years and where I did not needed to know further XML details. Unfortunately EasyXML is kind of weak in performance and CPU Load is high. This was not a problem as long as I had to generate some XML here and there, but now I have to generate , lets say, one hundred XML docs/strings per second and EasyXML can not handle it as expected. The Read Examples of libxml was very promising regarding the performance and I decided to use it. The downside is, complexity is far higher compared to EasyXML because you have to manage the XML on a very basic level and you not only have to learn the XML stuff, but also the functions of LibXML library itself.
The Read example which came alon with libxml is quite nice but in absence of a proper generate example I begun coding an generation example for myself which references to the W3C book example which is widely used as an example in many programming languages. So this is the actual result of the first tries to realize it. It does what I expected, but I am not 100% sure if it is effectively designed. In python for example there are slightly differences. So maybe an XML expert can browse through the code and search for some weaknesses.
For simplicity I put all vi's in a sequence and I bind no datastructure to it. All is very basic.
Here is the LibXML for Labview Library. Its latest version is also in VIPM. Thanks a lot to TroyK for the nice work !.
br,
Jörn
07-06-2015 06:33 AM - edited 07-06-2015 06:34 AM
I extend the example vi by a datastructure bookstore and dynamically parse this array into the xml structure.
There are two task I like to solve:
1. How can I get hte xml output in 'pretty printed' format ?. Now I have to use the editor for that purpose. I would like to have it as an option within the parsing process.
2. How can I realize the XML processing without creating a file. I would like to have it all in memory. The purpose is to send the xml doc directly (as string) to a socket (e.g. TCP Write) , and also retrieve a xml as string via a socket.
Jörn
07-07-2015 12:16 AM
To create an xml object in memory without a file use LibXML_ParseDoc.vi to create the doc reference instead of LibXML_OpenXMLFile.vi
You'll need the xmlDocDumpFormatMemory function to dump the xml string at the end. (attached)
If you set the format input to 1 and can somehow work out a way to set _xmlIndentTreeOutput in the xmlGlobalState struct to 1 then the output will be formatted with indents as you specified.
07-07-2015 09:01 AM
Thanks for the valuable input Troy. I extended the example in the way that you can choose 'File' or 'InMemory' creation of XML doc. At the output you can dump the XML from memory and saving to file in a sequence. You can also multiply the data to increase xml workload for benchmarking. The indent formating would be syntactic sugar and nice to have, I will give it a try later.
Jörn