Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to parse a *.xml do not use xml document widget in delphi? 1

Status
Not open for further replies.

zlbzeb

Programmer
Mar 17, 2006
2
CN
We want to write a class which can parse a xml file but not use the xml document widget,is there a good solution?Please give me some advise.
 
My advice is not to write your own code. It's a big job and has been done before.

Why do you want to write your own code to parse XML?

Andrew
Hampshire, UK
 
Thank you for your replay!
We want to make a .dll for our customer,so there is no Form.
1,I don't know if I can use the xmldocument widget without form.
2,If I use the sax,how can I complete the project.
 
you can use TXMLdocument without a form :

here's some code I use to load sectordata for a spacegame

Code:
procedure TXWorld.Load;

var XMLDoc : IXMLDocument;
    ANode : IXMLNode;
    Index : integer;
    XSector : TXSector;

begin
 try
  try
   XMLDoc:=TXMLDocument.Create(nil);
   XMLDoc.Filename:=STR_FILE_WORLDXML;
   XMLDoc.Active:=True;
   if (XMLDoc.DocumentElement.ChildNodes.Count > 0) then
   for Index:=0 to XMLDoc.DocumentElement.ChildNodes.Count-1 do
    begin
     ANode := XMLDoc.DocumentElement.ChildNodes[Index];
     Debug.output(Format('TXWorld.Load-> Loading Sector "%s"',[ANode.Attributes['Name']]));
     XSector:=TXSector.Create(ANode.Attributes['Name']);
     FSectors.Add(XSector);
     // load data for this sector
     XSector.Load(ANode);
    end;
  finally
   XMLDoc:=nil;  // dereference to kill the object since this is an interface
  end;
 except
  on E: Exception do
   Debug.Output(Format('TXWorld.Load-> Exception: "%s" ',[E.Message]));
 end;
end;

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top