var
Doc: TXMLDocument;
Child: TDOMNode;
j: Integer;
str: char;
begin
ReadXMLFile(Doc, 'F:\Code\yt\Lazarus\test\xml\teste.xml');
// using FirstChild and NextSibling properties
Child := Doc.DocumentElement.FirstChild;
while Assigned(Child) do
begin
Memo.Lines.Add(Child.NodeName + ' ' + Child.Attributes.Item[0].NodeValue);
Application.MessageBox(PChar('aho'), PChar(UTF8TOANSI(Child.Attributes.Item[0].NodeValue)),16);
// using ChildNodes method
with Child.ChildNodes do
try
for j := 0 to (Count - 1) do
begin
Memo.Lines.Add(Item[j].NodeName + ' ' + Item[j].FirstChild.NodeValue);
Application.MessageBox(PChar(Item[j].NodeName), PChar(Item[j].FirstChild.NodeValue),16);
end;
finally
Free;
end;
Child := Child.NextSibling;
end;
Doc.Free;
当我用Writeln输出Child.Attributes.Item[0].NodeValue时会报错,lz能否帮帮忙?
uses
Classes, SysUtils,
DOM, XMLRead, XMLWrite;
Var
Doc : TXMLDocument;
Child : TDOMNode;
j:Integer;
begin
ReadXMLFile(Doc,'xmlFile.xml');
//using FirstChild and nextSibling properties
Child := Doc.DocumentElement.FirstChild;
while Assigned(Child) do
begin
Writeln(Child.NodeName + ':' + Child.Attributes.Item[0].NodeValue);
//using ChildNodes method
with Child.ChildNodes do
try
for j:=0 to (Count - 1) do
begin
Writeln(Item[j].NodeName + ':' + Item[j].FirstChild.NodeValue);
end;
finally
Free;
end;
Child := Child.NextSibling;
end;
Doc.Free;
end.