如何使用OmniXML删除子节点?
问题描述:
我想删除行路径
部分中带有 pathid = 2
的行...
I'd like to delete the line with pathid="2"
in the rowpath
section...
<?xml version="1.0" encoding="utf-8"?>
<LostPath Condition="Active" Selected="train.exe" FullPathOfSelected="D:\mygames\arcade\train\" Selected="0">
<rowdir Name="train.exe" GamePath="D:\mygames\arcade\train\" Selected="0" />
<rowdir Name="othelo.exe" GamePath="D:\mygames\arcade\othello\" Selected="3"/>
<rowpath Name="train.exe" PathId="1" LevelPath="D:\mygames\arcade\train\levelpack1" levelsFound="27" />
<rowpath Name="train.exe" PathId="2" LevelPath="D:\mygames\arcade\train\levelpack21" levelsFound="19" />
<rowpath Name="othelo.exe" PathId="0" LevelPath="D:\mygames\arcade\othelo\levelpack1" levelsFound="11" />
</LostPath>
我该怎么做?
答
尝试使用此功能。
uses
OmniXML, OmniXMLUtils;
procedure TForm1.Button1Click(Sender: TObject);
var
XMLNode: IXMLNode;
XMLDocument: IXMLDocument;
begin
XMLDocument := CreateXMLDoc;
if XMLLoadFromFile(XMLDocument, 'XMLFile.xml') then
begin
XMLNode := XMLDocument.SelectSingleNode('/LostPath');
DeleteNode(XMLNode, 'rowpath[@PathId="2"]');
XMLDocument.Save('XMLFile.xml');
end;
end;