Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to parse an XML File/String in Delphi? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 6.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: S S B Magesh Puvananthiran 

How to parse an XML File/String in Delphi?


This is relevance to my previous article Importing XML DOM Parser Into Delphi.... 

In Delphi 6, there is a separate component to do the XML parsing in the Internet 
Palette, called TXMLDocument. With this component, we dont need to do any import 
like I mentioned in that article. The only thing you need is that you should have 
the relevant DLLs in your machine to do the parsing like MSXML.dll(Microsoft 
parser). You can use any parser as you wish. 

Now let us quickly review the properties and methods of this component. 


Itís a drop-down list containing the parsers available in your machine. If you have 
MSXML.dll in your machine, then you will see MSXML in that drop-down list. Itís 
nothing but the Microsoft parser. Like that if you have other parsers, then those 
will also be listed there. You can choose one. 

File Name or XML strings

You can either pass in a XML file or an XML string to that component. 

1   XMLDocument1.FileName := 'sample.xml'
2   XMLDocument1.XML.strings.add('an xml string');

Once you set these two properties, you can set the Active property to true; this 
initiates the parsing. Any errors during parsing will be captured by the Delphiís 
EDOMParseError exception. 

Also, you can save the XML document or strings into a separate file or memory 

3   XMLDocument1.SaveToFile('File Name');
4   XMLDocument1.SaveToStream(MemoryStream);

Getting the XML Data

Once the XML has been parsed without any parsing errors, you can get node details 
by using the method getElementsByTagName and properties like NodeName, NodeValue, 
NodeType etc., 

As I mentioned in that article, the DTD file should be in the search path as the application or should be in the path where the exe resides. Also you have to make sure that the XML file or string you are parsing should follow the DTDs mentioned in that DTD file. 

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC