ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

XML-INTO handling - in XML elements

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

  • XML-INTO handling - in XML elements

    I have a vendor whose XML has - in the xml element and cannot find a way to handle it. Can't have - in an rpg variable name and looking at the xml-into options I cannot see anything to handle it. Am I missing anything?

    Code:
    Dcl-S testXml varchar(32000);
    
           Dcl-Ds test;
             testvalue varchar(50);
           End-Ds;
    
           testXml = '<test><test-value>test it</test-value></test>';
    
           xml-into test %xml(testXml:'case=any');
    
           dsply testvalue;

  • #2
    Hello,

    You need to use "case=convert". This will convert XML tag names that aren't allowed as RPG variable names to something that is valid in RPG. In your case the XML "test-value" would be converted to RPG "test_value". Then you just have to update your DS to use a field named "test_value" and you'll be all set.

    For example:

    Code:
           Dcl-S testXml varchar(32000);
    
           Dcl-Ds test;
             test_value varchar(50);
           End-Ds;
    
           testXml = '<test><test-value>test it</test-value></test>';
    
           xml-into test %xml(testXml:'case=convert');
    
           dsply test_value;

    Comment


    • #3
      Thank you.

      Comment

      Working...
      X