2

我想删除该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>

我怎样才能做到这一点 ?

4

2 回答 2

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;
于 2011-09-29T10:07:31.647 回答
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;
于 2011-09-30T06:56:00.407 回答