본문 바로가기
Application/Delphi Lecture

xml 데이타 읽기

by 현이빈이 2008. 8. 13.
반응형

var
  XMLDOM : IXMLDOMDocument;
  NodeList : IXMLDOMNodeList;
  i : Integer;
begin
  XMLDOM := CoDomDocument.Create;
  try
    //XMLDOM.loadXML(cstr);
    XMLDOM.load('d:\test.xml');
    NodeList := XMLDOM.selectNodes('/ExecuteList/Execute[@name="Result"]');
    for i := 0 to NodeList.length - 1 do
//      Memo1.Lines.Add((NodeList.item[i].attributes.item[0].nodevalue);
//      Memo1.Lines.Add('Description = ' + (NodeList.item[i] as IXMLDomElement).attributes.get .attributes.getNamedItem('Description').nodeValue );
      Memo1.Lines.Add((NodeList.item[i] as IXMLDomElement).text);
  finally
    NodeList := nil;
    XMLDOM := nil;
  end;

test.xml

-----------------------------------------------------------------------------

<?xml version="1.0" encoding="euc-kr"?>
<ExecuteList>
 <Execute name="Result" description="Connection Execute Result">OK</Execute>
 <Execute name="ExecuteCnt" description="Connection Execute Result Count">3</Execute>
</ExecuteList>

반응형