ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

XML-INTO: How Do You Get Both XML array element value and attribute?

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

  • XML-INTO: How Do You Get Both XML array element value and attribute?

    I tried accomplishing some XML parsing using XMLTABLE that I could not figure out so I thought about switching to XML-INTO. However, I think I am running into the same problem. Take the following XML document:

    Code:
    <Things>
    <Thing ID="1">
    <Name>Thing1</Name>
    <Values>
    <Value Attribute="FieldName1">YADDA YADDA YADDA</Value>
    <Value Attribute="FieldName2">SO ON AND SO FORTH</Value>
    <ValueList Attribute="FieldName3">
    <Value>CA</Value>
    <Value>NY</Value>
    <Value>TX</Value>
    </ValueList>
    <ValueList Attribute="FieldName4">
    <Value>US</Value>
    <Value>CA</Value>
    <Value>GB</Value>
    </ValueList>
    </Values>
    </Thing>
    <Thing ID="2">
    <Name>Thing2</Name>
    <Values>
    <Value Attribute="FieldName1">YADDA YADDA YADDA</Value>
    <Value Attribute="FieldName2">SO ON AND SO FORTH</Value>
    <ValueList Attribute="FieldName3">
    <Value>CA</Value>
    <Value>NY</Value>
    <Value>TX</Value>
    </ValueList>
    <ValueList Attribute="FieldName4">
    <Value>US</Value>
    <Value>CA</Value>
    <Value>GB</Value>
    </ValueList>
    </Values>
    </Thing>
    </Things>
    How do I set up the proper data structures so that I can get the data for the value of a tag and and attribute of the tag when they are a child array of a parent?


    Code:
    <Values>
    <Value Attribute="FieldName1">YADDA YADDA YADDA</Value>
    <Value Attribute="FieldName2">SO ON AND SO FORTH</Value>
    </Values>

    I think what I am looking for is:

    Values.Value.Attribute = 'FieldName1'
    Values.Value = 'YADDA YADDA YADDA'





  • #2
    I am able to get the Values.Value using the following data structure:


    PHP Code:
    dcl-ds Values qualified;
      
    Value varchar(64dim(10);
    end-ds;

    dcl-ds Thing qualified;
      
    ID varchar(64);
      
    Name varchar(64);
      
    Values likeds(Values);
    end-ds
    Just not sure how to get both Values.Value and Values.Value.AttributeID.

    Comment


    • #3
      I think I finally found it: need to use the datasubf option.

      Examples of the datasubf option - IBM Documentation

      Comment


      • #4
        You are correct - that is exactly what you need to do.

        I've written a lot on the use of XML-INTO (and DATA-INTO) many of the XML-INTO articles are in this collection: https://authory.com/JonParisAndSusan...XML-Processing

        Comment


        • #5
          Thanks Jon. I didn't have the proper language to describe the problem via a Google search so it took me a while (been working on it since late yesterday).

          Comment

          Working...
          X