Вот такие заморочки там встречаются, пытаюсь победить "offset", "type", "value":
Код HTML:
<?xml version="1.0" encoding="UTF-8"?>
<mime-types>
<mime-type name="application/andrew-inset">
<ext>ez</ext>
</mime-type>
<mime-type name="application/pdf"
description="Portable Document Format (PDF)">
<ext>pdf</ext>
<magic offset="0" value="%PDF-"/>
</mime-type>
<mime-type name="application/vnd.mif"
description="FrameMaker Interchange Format">
<ext>mif</ext>
<magic offset="0" type="byte" value="3c4d494646696c6520"/>
</mime-type>
<mime-type name="application/postscript"
description="PostScript (PS)">
<ext>ps</ext><ext>ai</ext><ext>eps</ext>
<magic offset="0" value="%!"/>
<magic offset="0" value="\004%!"/>
</mime-type>
</mime-types>
Код:
procedure TForm1.Button4Click(Sender: TObject);
var
doc: IXmlDocument;
rootNode: IXMLNode;
I, J: Integer;
S: string;
begin
Memo1.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//added
Memo2.Lines.Add(rootNode.ChildNodes[i].Attributes['description']);//added
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);
//
//added, not worked
if rootNode.ChildNodes[i].ChildNodes[J].NodeName = 'magic' then
begin
if rootNode.ChildNodes[i].HasAttribute('offset') then
s := rootNode.ChildNodes[i].Attributes['offset'];
if rootNode.ChildNodes[i].HasAttribute('type') then
s := S + '/' + rootNode.ChildNodes[i].Attributes['type'];
if rootNode.ChildNodes[i].HasAttribute('value') then
s := S + '/' + rootNode.ChildNodes[i].Attributes['value'];
Memo2.Lines.Add(s);
end;
//
end;
Memo2.Lines.Add('------------------------------------');
end;
end;
finally
doc := nil;
end;
end;