Тема: Парсинг XML
Показать сообщение отдельно
  #7  
Старый 10.04.2019, 12:14
Аватар для Vayrus
Vayrus Vayrus вне форума
Исполняемый Ретровирус
 
Регистрация: 09.08.2008
Адрес: Umbrella Corporation
Сообщения: 743
Репутация: 1293
По умолчанию

Спасибо, выручил

Код:
procedure TForm1.Button4Click(Sender: TObject);
var
  doc: IXmlDocument;
  rootNode: IXMLNode;
  i, J: integer;
  s: string;
begin
  Memo2.Lines.Clear;
  doc := TXMLDocument.Create(nil);
  try
    doc.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'mime-types.xml');
    doc.Active := true;
    doc.ChildNodes.FindNode('mime-types');
    rootNode := doc.ChildNodes.FindNode('mime-types');
    if rootNode.ChildNodes.Count = 0 then
      EXIT;
    for i := 0 to rootNode.ChildNodes.Count - 1 do
    begin
      if rootNode.ChildNodes[i].NodeName = 'mime-type' then
      begin
        Memo2.Lines.add(rootNode.ChildNodes[i].Attributes['name']);
        if rootNode.ChildNodes[i].HasAttribute('description') then
          Memo2.Lines.add(rootNode.ChildNodes[i].Attributes['description']);
        for J := 0 to rootNode.ChildNodes[i].ChildNodes.Count - 1 do
        begin
          if rootNode.ChildNodes[i].ChildNodes[J].NodeName = 'ext' then
            Memo2.Lines.add('  ' + rootNode.ChildNodes[i].ChildNodes[J]
              .NodeValue);
          //
          if rootNode.ChildNodes[i].ChildNodes[J].NodeName = 'magic' then
          begin
            s := '';
            if rootNode.ChildNodes[i].ChildNodes[J].HasAttribute('offset') then
              s := rootNode.ChildNodes[i].ChildNodes[J].Attributes['offset'];
            if rootNode.ChildNodes[i].ChildNodes[J].HasAttribute('type') then
              s := s + '/' + rootNode.ChildNodes[i].ChildNodes[J].Attributes['type'];
            if rootNode.ChildNodes[i].ChildNodes[J].HasAttribute('value') then
              s := s + '/' + rootNode.ChildNodes[i].ChildNodes[J].Attributes['value'];
            Memo2.Lines.add(s);
          end;
          //
        end;
        Memo2.Lines.add('------------------------------------');
      end;
    end;
  finally
    doc := nil;
  end;
end;
Ответить с цитированием