SPSS Statistics

SPSS Statistics

Your hub for statistical analysis, data management, and data documentation. Connect, learn, and share with your peers! 

 View Only
  • 1.  XML custom table to output window

    Posted Thu November 30, 2023 09:28 AM
    Edited by Soren V. Raben Thu November 30, 2023 09:56 AM

    I have a set of custom tables where each table has to be formatted individually. I'm writing a Python script. I've managed to extract XML chart (in other words XML script) for each table however, I can't find a way to insert formatted XML to output window. Is there any solution? I'm aware of `OUTPUT CREATE` command but it requires JSON which schema is not compatible with XML chart (meaning, when I use `xmltodict` Python external library, I can't simply put this dictionary (hence JSON) into `OUTPUT CREATE`). So, alternatively, is there any way to extract JSON directly from output window (using OMS or `OUTPUT EXPORT`) - OR - any tool to convert easily this XML chart/Python dictionary extracted from XML to StatJSON 2.0 schema?



  • 2.  RE: XML custom table to output window

    Posted Thu November 30, 2023 09:55 AM
    There is no direct way to create or replace a table using XML  You can retrieve the XML representation from the Viewer or via OMS, but you would have to use the general pivot table apis to modify the table.

    If you can explain more about what you are trying to produce, there  might be an alternative way to do it.

    You can set charts via the chart xml apis, but those do not deal with pivot tables.

    --





  • 3.  RE: XML custom table to output window

    Posted Thu November 30, 2023 11:03 AM

    Thanks Jon.

    This special formatting mostly deals with relocating some values from columns to rows, deleting certain columns and - most importantly - merging proportional comparison test into one table (`CTABLES` syntax does not offer satisfying results, not to mention that when results of comparison are automatically merged they are different than divided into two separate custom tables!).

    I've just found statjson.py module in util folder (in site-packages) and I find it to may be possibly useful. Are there any examples how to use this API? In general, StatJSON and `OUTPUT CREATE` documentation lacks of good, various examples. If I'm wrong - where should I look for them?

    Last but not least - do SPSS developers plan to implement (via `OMS` or `OUTPUT EXPORT`) feature to convert output elements to JSON? On the other hand, a Python module for extraction/conversion from XML would do a great job (I hope).




  • 4.  RE: XML custom table to output window

    Posted Thu November 30, 2023 11:27 AM

    A few of the newer extension commands use statjson and work with json instead of xml. I don't know of plans to extend this, but I am not in on the planning process.  Maybe someone else can comment.

    JSON output from OMS would be really useful.  There are Python libraries such as xmljson and ElementTree that could be useful here..  (STATS PACKAGE INSTALL PYTHON=xmljson.)  You probably know about those already.



    ------------------------------
    Jon Peck
    ------------------------------



  • 5.  RE: XML custom table to output window

    Posted Thu November 30, 2023 01:21 PM
    I should have added that moving values around, deleting columns, and merging tables can all be done with Python pivot table apis and/or existing extension commands.  As for differing results, the first place to look is the impact of missing values.--





  • 6.  RE: XML custom table to output window

    Posted Fri December 01, 2023 01:24 PM

    The problem is that converting pivot table's XML chart to dictionary (not exactly JSON) won't be compatible with StatJSON schema. So in fact I can't do anything meaningful with either XML (can't 'reupload' chart to output window) or JSON (first I need to convert it to StatJSON but the documentation is insufficient). I hope that a generator/converter to StatJSON will be taken into consideration during development of future releases.