Home AMX User Forum AMX General Discussion
Options

XML export.

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.

Comments

  • Options
    youstrayoustra Posts: 135
    Take a look at Exchanger XML

    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
  • Options
    youstrayoustra Posts: 135
    XML Fox

    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
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Well, here are a few I found:

    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
  • Options
    youstrayoustra Posts: 135
    I'm having some weird results dealing w/ my xml files.

    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
    KP2.txt 22.8K
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    Actually, I found out that notepad++ wasn't doing the formatting. In the process of checking out the programs, there was one that was automatically doing the formatting. It's called XMLViewer and it's by Mindfusion. It's free, but the editing capabilities are sorely lacking.

    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
  • Options
    youstrayoustra Posts: 135
    An update: XML Fox appears the winner. It has a convenient "grid mode" that lets you edit the xml in a spreadsheet-like interface.

    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
  • Options
    DHawthorneDHawthorne Posts: 4,584
    There's not supposed to be a possibility for "non-Netlinx-XML-compatible" XML. That's the whole point of XML, it's a standard format. The absolute worse that's supposed to happen is there is data in it that cannot be interpreted because NetLinx doesn't recognize it, the format should not ever be an issue.

    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.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    youstra wrote:
    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 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
  • Options
    youstrayoustra Posts: 135
    If you go var_to_xml and back you're generally fine, even if you edit the file w/ notepad (regular old text editing).

    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:
    - <array>
    <curLength>0</curLength>
    - <array>
    <index>1</index>
    <curLength>11</curLength>
    <string>Hello World</string>
    </array>
    - <array>
    <index>2</index>
    <curLength>11</curLength>
    <string>Hello Line2</string>
    </array>
    - <array>
    <index>3</index>
    <curLength>11</curLength>
    <string>Hello Line3</string>
    </array>
    </array>

    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:
    - <array>
    <curLength>0</curLength>
    - <array>
    <curLength>11</curLength>
    <index>1</index>
    <string>Hello Line1</string>
    </array>
    - <array>
    <curLength>11</curLength>
    <index>2</index>
    <string>Hello Line2</string>
    </array>
    - <array>
    <curLength>11</curLength>
    <index>3</index>
    <string>Hello Line3</string>
    </array>
    </array>

    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.

    capture.jpg

    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
  • Options
    youstrayoustra Posts: 135
    One clarification from previous note. The hyphens are not part of the XML - they're just the bullet points that XML Fox uses.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    It sounds like XML Fox might be the cause of the problem then. I used XML Viewer to open the file initially (because I think it simply adds CR/LF after each item and tabs as necessary). Then I opened the file in notepad++ and I get a somewhat structured view of the file. I was able to make quite a few edits and then import the changed file with no problem. I agree that the change in position of the various tags is probably causing you problem.

    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
  • Options
    youstrayoustra Posts: 135
    Jeff - you're absolutely correct. I never would've guessed XML Fox would have such an idiotic bug...I figured it was some exotic implied XML rule that I was unaware of.

    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
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    XMLPad
    youstra wrote:
    I'm using a different editor called XMLPad from WMHelp. It's free and awesome? Hope this helps others
    I?ve been following this thread with considerable interest and XMLPad is the winner for me. Thanks for the research and feedback guys.
  • Options
    viningvining Posts: 4,368
    The XMLpad is pretty nice. I personally lik the table view. Thanks for finding it.

    Spire_Jeff wrote:
    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

    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?
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    I just used a very large char array. Didn't seem to have any problems.

    Jeff
  • Options
    viningvining Posts: 4,368
    Spire_Jeff wrote
    I just used a very large char array. Didn't seem to have any problems.
    What was the resulting file size? Was that a regular VAR or a buffer VAR?

    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.
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    I'll have to find the program and check it out. Currently I am only dealing with preset data, but in the past I was dealing with a device in which I was tracking a much more information and I recall the file being somewhere in the 20k range. I will try to find the code snippet and post it.

    Jeff
Sign In or Register to comment.