我想在pathid="2"
部分删除rowpath
行...
<?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>
我该怎么做?
答案 0 :(得分:4)
尝试使用它。
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;
答案 1 :(得分:2)
如何删除具有相同属性值的所有节点 的方法很少。这是其中之一。但是 请注意,这篇文章没有回答这个问题 。它应该被问为另一个问题。
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');
DeleteAllChildren(XMLNode, 'rowpath[@Name="train.exe"]');
XMLDocument.Save('XMLFile.xml');
end;
end;