Thursday 11 May 2017

PeopleCode: How To Remove Tags With Blank Values From XML File

Wish there was an easy way of parsing an XML file using PeopleCode without having to write all these loops.
Here's a quick function that removes xml tags with no value (blank, nulls.. zeroes excluded).

Function CleanNode(&inXMLDoc)
   
   Local number &i;
   Local array of XmlNode &dataList;
   
   &dataList = &inXMLDoc.GetElements();
   For &i = &dataList.Len To 1 Step - 1
      If None(&dataList [&i].NodeValue) Then
         If &dataList [&i].ChildNodeCount = 0 Then
            &inXMLDoc.removeChildNode(&i);
         End-If;
      End-If;
   End-For;
   
End-Function;

Specify a parent node as parameter and you're done.

No comments:

Post a Comment