XML export.
Spire_Jeff
Posts: 1,917
I am currently working on a module that requires a fair amount of configuration information. I have used the VARIABLE_TO_XML and XML_TO_VARIABLE functions to succesfully import/export the main variables I need populated, but I am having difficulty finding an XML viewer/editor that allows me to easily edit the XML files. Anyone know of anything that works well?
Thanks,
Jeff
P.S.
I am dealing mainly with multidimensional arrays of structures.
Thanks,
Jeff
P.S.
I am dealing mainly with multidimensional arrays of structures.
0
Comments
I'm facing the same thing right now. The closest thing I've seen is Exchanger (exchangerxml.com), but it's pretty clunky and over featured for what I need. I'll keep digging and report back.
I'm very curious what others have found. I've just started using it, but so far AMX's var-to-xml stuff looks sweet, esp for complex data structures.
-Bill
Been digging further - XML Fox looks good enough to go with for me. www.xmlfox.com.
Anyone else who's editing XML, please let us know what you're using.
-Bill
XMLSpy Home version - looks like a very indepth XML editor, unfortunately the XML encoding done by Netlinx doesn't allow any of the cool looking windows to display any information turning this large app into a glorified text editor with formating (from what I've seen).
MindFusion's XML Viewer - Simple app with potential, but the inability to directly edit the source makes this product to cumbersome. You have to click on EVERY value you wish to change and edit it in a popup window..... not very appealing when dealing with changing 8*25*7 values
Peter's XML Editor - Simple app, does allow editing in a formated source view, but doesn't seem to offer anything more than formatting the file with colors and tabs.
XML Fox - Simple app, but doesn't seem to offer anything more than formatting the file with colors and tabs.
Notepad++ (or Notepad Plus) - Simple app that adds color and tab formatting, but also allows element collapsing (very similar to Netlinx Studio). I think this is going to be my choice for the time being.
Hope one of these works out for anyone else that needs to edit the XML exports.
Jeff
I tried notepad++ with my xml file generated via netlinx and it just took the file as a single long string. No parsing into a tree or grid, which is what I really need.
In IE, it shows the indented view as it should. Same thing in XML Fox, but it doesn't show grid or tree mode.
When I pull in other XML files to notepad++, they show up just fine.
Jeff, since you got notepad++ to work for you, I'm assuming I've done something wrong or am missing something.
I'm not experienced w/ XML, so I'm not sure what's up.
Possibilities:
1 - there's some setting in notepad++ that I'm missing
2 - i've screwed up my var-to-xml code
3 - my data structure doesn't lend itself to tree/grid parsing in an xml viewer like notepad++ (although it looks fine in IE)
I attached the .xml but had to rename it .txt for the bulletin board. If my mistake is #1 and someone can pull this into notepad++ and tell me the setting I'm missing, I'd be greatly appreciative.
Here's my data structure and my xml-writing code:
structure DMSStatus
{
char strPlanID[8] // Code from plan, ex: KP1.06.3
char strPlanLoc[10] // Plain english location
char strLutronLiteKeypad[8] // Lutron phantom kpd code
char nZone // index into zone array
integer iFlagSubMenuEnabled // bit flags enabling sub-menus
}
...
DMSStatus _sKPStatus[DMS_KPD_COUNT]
VOLATILE char sXMLString[50000] // for XML file writing
VOLATILE slong slReturn
VOLATILE slong slFile
...
slReturn = variable_to_xml(_sKPStatus, sXMLString, 1, $00)
slFile = FILE_OPEN('KP.xml',nFILE_WRITE)
if (slFile > 0) {
slReturn = FILE_WRITE(slFile, sXMLString, LENGTH_STRING(sXMLString))
if (slReturn < 0) SEND_STRING 0, "'FILE WRITE FAIL RTN=', ITOA(slReturn)"
slReturn = FILE_CLOSE(slFile)
if (slReturn < 0) SEND_STRING 0, "'FILE CLOSE FAIL RTN=', ITOA(slReturn)"
Thanks for any help anyone can offer.
-Bill
What I did was simply open all of the files I needed to edit with the viewer, then in notepad++ and everything was formatted.
I still think I might just write a simple app to populate the data on a touch panel and then just write the structure to disk. Honestly, I think I can whip up a quick module to handle it quicker then pouring through the file in notepad++
TKN
But there's another problem: I created the base xml file by hard-coding some values and spitting the entire array out via var_to_xml.
Then edit the file in XML Fox and recode the same routine to read the file in via xml_to_var.
But when I execute the code, Netlinx gives a -2 runtime error on the var_to_xml, which is: "Decode data too small, decoder ran out of data. Most likely poorly formed XML."
I don't know if I'm reading wrong or if XML Fox is saving the file in a non-Netlinx-XML-compatible flavor.
So here's the question: Has anyone used this XML stuff? I'd love whatever tips you might have -- which XML editor to use. What traps to avoid. Any code snippets?
I've got more testing to do. I'll put updates here.
-Bill
One of two things happened here: your XML editor didn't really save the data in proper XML format, or there is a bug in the NetLinx interpretor that is causing the error.
I have used the XML_TO_VAR and VAR_TO_XML successfully, so it does work. I also encountered an error the first time I attempted it, but I don't recall the exact error I had. Check the size of the variable you are creating to hold the XML file. The XML File can get large (in relation to normal netlinx variable sizes). The largest file I have dealt with thus far has been around 280k, so I had to change the variable holding the VAR_TO_XML result to sTEMP_XML[290000]. Once I increased the size of the variable, everything worked fine. You might also need to export the variable again to get the missing info.
I'll have to check out XML Fox again and see if I can find the grid view. I could have sworn it didn't work for me tho.
Jeff
The problem is if you use any XML editor out there. XML Fox was the only one that I found that read the file in and allowed editing in any structured way. Other XML editors saw it as one long string.
But in XML Fox, if you edit it, XML Fox automatically changes the structure of the XML file slightly. This new structure is something that those other XML editors now read and happily interpret in a structured way.
But now when you try to go xml_to_var, Netlinx is all confused.
That's why earlier, I suspected that Netlinx had some not-quite-kosher XML variant. It works great if you're grunting it out in notepad, or just backing up the data. But once you want to interact w/ some XML editor, the rest of the world sees things differently.
Here's the example. I created a 3x11 char array. var_to_xml produced this faithfully:
This could be read back into Netlinx w/ xml_to_var, no problem.
But if I change any data point - in this case, the first string, XML Fox automatically rejiggers the whole file to this:
Notice that before, straight from Netlinx, index was before curLength. Afterward, they're reversed. That's enough to cause the problems. XML Fox does it automatically - like it's correcting some problem.
Further, XML Fox shows a schema as below with curLength before index -- this is the case when it first reads the file (and index is actually before curLength as shown in the first quote), AND after an edit which triggers XML Fox's rejiggering. The schema never changes....but the XML does.
I'm not sure many will be able to help here, but I'm hoping some righteous AMX engineer lurking in the shadows will pipe in and help me out.
-Bill
On a seperate note, how difficult would it be to add the ability to edit XML files (generated by Netlinx) within Netlinx Studio 2? We already have collapsible code (Could provide collapsing points at <INDEX> and maybe a couple other tags). The only other thing I could see being needed would be a parser that inserts CR/LF and tabs. Or am I missing something?
Jeff
It all works now, and I'm using a different editor called XMLPad from WMHelp. It's free and awesome - nice grid mode for changing values w/ very few keystrokes.
It has no problem opening the AMX unformatted file, and it doesn't insist on formatting it when it saves -- many editors do this as a "favor" and end up adding tons of spaces, nearly doubling the filesize. It can also open a file w/ a URL address, so you can look at a file w/o having to transfer it.
Hope this helps others.
-Bill
I?ve been following this thread with considerable interest and XMLPad is the winner for me. Thanks for the research and feedback guys.
Spire_Jeff wrote:
Did you create a buffer out of that variable to hold that amount of data or was it just a char array?
I've just started playing with this to hold data from module which I can't make persistent and to convert my structure to xml which is presently sized for just 3 T-Stats is 22k so a home or a business with 12 - 30 or the ViewStat max of 60 would be one huge file.
I tried Variable _to_string thinking binary would be a smaller file but much to my dismay it was actually larger. Does anyone know why?
Jeff
I have the 22k file working but I'm using a buffer and I didn't go backwards and try a regular VAR one I made the conatianer big enough to work.
That's the deep structure I reference before which is used in the VST_Scheduler and that looks pretty cool in the table view of XMLpad.
Jeff