Skip Empty XML-Tags

bluesky29bluesky29 Member Posts: 29
edited 2007-06-11 in NAV Tips & Tricks
on demand here is the code to skip empty xml-tags after using a xml-port:

DeleteEmptyXMLNodes(VAR XMLNode : Automation "'Microsoft XML,v3.0'.IXMLDOMNode")
IF XMLNode.nodeTypeString = 'element' THEN BEGIN
IF (XMLNode.hasChildNodes = FALSE) THEN BEGIN
IF (XMLNode.xml = '<' + XMLNode.nodeName + '/>') THEN
XMLNode := XMLNode.parentNode.removeChild(XMLNode)
END ELSE BEGIN
XMLDomNodeList := XMLNode.childNodes;
FOR i := 1 TO XMLDomNodeList.length DO BEGIN
XMLChildNode :=XMLDomNodeList.nextNode();
DeleteEmptyXMLNodes(XMLChildNode);
END;
END;
END;

following local variables:
XMLChildNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode
XMLDomNodeList Automation 'Microsoft XML, v3.0'.IXMLDOMNodeList
i Integer

you can use it with an existing xml-document like that:

CurrNode Automation 'Microsoft XML, v3.0'.IXMLDOMNode

CurrNode := XMLDOMDocument.documentElement;
DeleteEmptyXMLNodes(CurrNode);

sorry that the code isnt indented but html cannot be turned on for my posts ?!?

Comments

  • krikikriki Member, Moderator Posts: 9,112
    bluesky29 wrote:
    sorry that the code isnt indented but html cannot be turned on for my posts ?!?
    BCC code and HTML code you can setup in your profile.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


Sign In or Register to comment.