Ein Knoten hat die Eigenschaft NodeType. Und wenn dieser
NodeType = TNodeType.ntComment
ist, dann ist der Knoten ein Kommentar.
Delphi-Quellcode:
program Project5;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
WinApi.ActiveX,
Xml.XmlIntf,
Xml.XmlDoc
;
procedure justXmlThings();
const
xmlContent = '
<root><node1/><!-- this is a comment --><node2/></root>';
var
nodes: IXMLNodeList;
nodeIndex: Integer;
node: IXmlNode;
begin
nodes := LoadXMLData(xmlContent).DocumentElement.ChildNodes;
for nodeIndex := 0
to Pred(nodes.Count)
do begin
node := nodes.Get(nodeIndex);
if (node.NodeType <> TNodeType.ntComment)
then
WriteLn(node.NodeName);
end;
end;
begin
try
CoInitializeEx(
nil, COINIT_APARTMENTTHREADED);
try
justXmlThings();
finally
CoUninitialize();
end;
except
on E:
Exception do
Writeln(E.ClassName, '
: ', E.
Message);
end;
WriteLn('
end.'); readln;
end.