Hallo himitsu!
Ich versuche gerade himXML in einem anderen Projekt einzusetzen.
Dabei stellt sich mir die Frage, wie komme ich an die Attribute eines Nodes.
Delphi-Quellcode:
procedure TTag.LoadFromFile(const AFilename: string);
var
f : TXMLFile;
begin
Parent := nil;
// öffnen bla bla
f := TXMLFile.Create;
try
f.LoadFromFile(AFilename);
LoadFromNode(f['virtualroot\root']);
finally
f.Free;
end;
end;
procedure TTag.LoadFromNode(const AXMLNode: TXMLNode);
var
na : string;
i, ty: Integer;
t : TEntry;
nds : TXMLNodeArray;
begin
Name := AXMLNode.Node['name'].Text;
nds := AXMLNode.NodeList['files\file'];
for i := 0 to High(nds) do
begin
ty := nds[i]['@type'].Text;
// Directory Node
if (ty and 1) = 1 then
begin
t := TTag.Create;
FChilds.Add(t);
t.Parent := Self;
TTag(t).LoadFromNode(nds[i]);
end else
begin
t := TEntry.Create;
FFiles.Add(t);
t.Name := nds[i]['name'].Text;
end;
t.Hidden := (ty and 2) = 2;
end;
end;
Die Datei sieht dabei so aus:
XML-Code:
<?
xml version="1.0" encoding="UTF-8" standalone="yes"?>
<taxs>
<virtualroot>
<root>
<name>Root</name>
<files>
<!-- Filecontainer with "filetype"
Bit Meaning (if set)
1 Directory
2 Hidden -->
<file type=1>
<name>Sub</name>
<files>
<file type=3>
<name>HiddenSub</name>
</file>
<file type=1>
<name>Sub</name>
<files>
<file type=2>
<name>HiddenFile</name>
<original>C:...</original>
</file>
</files>
</file>
</files>
</file>
<file type=0>
<name>Filetest</name>
<original>C:...</original>
</file>
</files>
</root>
</virtualroot>
</taxs>
Wenn ich nun die Zeile 28 ausführe um den
Type des Nodes "taxs\virtualroot\root\files\file[0]" zu kommen.
Zitat:
---------------------------
text
---------------------------
[EXMLException] TXMLNodeList.Add:
invalid name ("@type")
---------------------------
OK
---------------------------
MfG
xZise