如何使用 OmniXML 删除子节点?

发布于 2024-12-07 07:31:12 字数 799 浏览 0 评论 0原文

我想删除 rowpath 部分中带有 pathid="2" 的行...

<?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>

我该怎么做?

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>

How can I do that ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

子栖 2024-12-14 07:31:12

尝试使用这个。

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;

Try to use this.

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;
神经大条 2024-12-14 07:31:12

有几种方法如何删除具有相同属性值的所有节点。这是其中之一。但请注意,这篇文章并没有回答这个问题。它应该作为另一个问题来问。

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;

There are few ways how to delete all nodes with the same attribute value. Here's one of them. But please note, this post doesn't answer this question. It should be asked as another question.

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文