sponsored links

Collapse

Announcement

Collapse
No announcement yet.

xml-into processing extra elements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • xml-into processing extra elements

    Just wondering if it is possible to get extra elements and put them into a data structure for processing. Hopefully this makes sense.

    Code:
    Dcl-S inXml varchar(32000);
    
           Dcl-Ds test qualified;
             item char(12);
             Dcl-Ds elements dim(10);
             name varchar(100);
             value varchar(100);
             end-Ds;
           End-Ds;
    
           inxml = '<test><item>abcdef</item><field1>test1</field1><field2>test2 +
                    </field2></test>';
    
           xml-into test %xml(inxml);
    
           //test.elements(1).name would be field1
           //test.elements(1).value would be test1
    
           //test.elements(2).name would be field2
           //test.elements(2).value would be test2

  • #2
    Simple answer is no.

    For XML-INTO the "shape" of the DS must match the "shape" of the XML.

    More to the point, what you appear to be trying to set into the DS array are the element names _and_ their values. Is that what you want?

    If so then XML-SAX is what you need not XML-INTO.

    Comment


    • #3
      Yes that is what I want, I'll look into xml-sax.

      Explanation is that I currently have about 20 item attributes where the element name correlates to a sequence number in a table, so I would have to code a select statement to handle them. I created a table with the name and sequence #. If I had the structure above I could just loop through and look up the sequence number instead. If it was only ever going to be 20 then not that big of a deal but we currently have 125 that this could expand to.

      Thought it would be cool if the right scenario came up in the future where all the names were stored and there was an associated sql statement stored to handle the value.

      Comment


      • #4
        The other way to do it would be to actually code them as attributes (or elements for that matter) and use the countprefix option to allow you to tell which had been populated.

        I've written a couple of things on XML-SAX - this is the latest https://www.itjungle.com/2016/06/14/fhg061416-story01/

        This one includes a utility program that prints out what it finds in an XML document https://www.mcpressonline.com/progra...has-sax-appeal.

        Comment

        Working...
        X