delete the Empty Nodes in XML port through code unit with using Dot net variable.

Hi I need to delete the Empty Nodes in XML port through code unit with using Dot net variable. Is my code is correct ? kindly suggest some answers.



Documentation()

OnRun()
Document:= Document.XmlDocument();
Document.Load('D:\xml\xmlportforexport.xml');
Parentnode:= Document.SelectSingleNode('Root');
Nodelist:= Parentnode.ChildNodes();
FOR I := 0 TO Nodelist.Count -1 DO BEGIN
Childnode := Nodelist.ItemOf(I);
CASE Childnode.Name OF
'Tablename':
BEGIN
Childnodelist:= Childnode.ChildNodes();
FOR J := 0 TO Childnodelist.Count -1 DO BEGIN
Childnode:= Childnodelist.ItemOf(J);
Deletingfunction(Childnode);
END;
END;
ELSE
BEGIN
END;
END;
END;
MESSAGE('done');

LOCAL Deletingfunction(Nodes : DotNet "System.Xml.XmlNodeList")
Nodes:= XMLDoc.ChildNodes;
FOR A := 0 TO Nodes.Count -1 DO BEGIN
DOMNode:= Nodes.Item(A);
END;
XMLDoc:= XMLDoc.XmlDocument;
XMLDoc.Load('D:\xml\xmlportforexport.xml');
Nodes:= XMLDoc.SelectSingleNode('/name');
FOR A := 0 TO Nodes.Count -1 DO BEGIN
XMLNode1:= Nodes.Item(A);
XMLNode1:= Nodes.Item(A);
XMLNode1.ParentNode().RemoveChild(XMLNode1);
END;
XMLDoc.Save('D:\xml\xmlportforexport2.xml');
MESSAGE('Work delted');

Answers

  • ExploreExplore Member Posts: 14
    This is a Pseudocode that you can customize to meet your specific requirements.
    DeleteEmptyNodes(VAR Document: DotNet "'System.Xml.XmlDocument'");
    VAR
      ParentNode: DotNet "'System.Xml.XmlNode'";
      NodeList: DotNet "'System.Xml.XmlNodeList'";
      I, J: Integer;
    BEGIN
      Document := Document.XmlDocument();
      Document.Load('D:\xml\xmlportforexport.xml');
      
      ParentNode := Document.SelectSingleNode('Root');
      NodeList := ParentNode.ChildNodes();
      
      FOR I := NodeList.Count - 1 DOWNTO 0 DO BEGIN
        ChildNode := NodeList.ItemOf(I);
        CASE ChildNode.Name OF
          'Tablename':
            BEGIN
              ChildNodeList := ChildNode.ChildNodes();
              FOR J := ChildNodeList.Count - 1 DOWNTO 0 DO BEGIN
                ChildNode := ChildNodeList.ItemOf(J);
                DeletingFunction(ChildNode);
              END;
            END;
        ELSE
          BEGIN
          END;
        END;
      END;
      
      Document.Save('D:\xml\xmlportforexport2.xml');
      MESSAGE('Deleted');
    END;
    
    DeletingFunction(Nodes: DotNet "'System.Xml.XmlNodeList'");
    VAR
      XMLDoc: DotNet "'System.Xml.XmlDocument'";
      XMLNode: DotNet "'System.Xml.XmlNode'";
      K: Integer;
    BEGIN
      XMLDoc := Nodes.XmlDocument;
      Nodes := XMLDoc.ChildNodes;
      
      FOR K := Nodes.Count - 1 DOWNTO 0 DO BEGIN
        XMLNode := Nodes.Item(K);
        XMLNode.ParentNode().RemoveChild(XMLNode);
      END;
    END;
    
Sign In or Register to comment.