How do I remove a child node using OmniXML?

I would like to remove the line with pathid="2"

in the section 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>

      

How can i do this?

+2


source to share


2 answers


Try using 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;

      

+4


source


There are several ways to remove all nodes with the same attribute value . Here is one of them. But please note that this post does not 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;

      

+2


source







All Articles