Delphi in Creating, Manipulating and Parsing XML

How to use Delphi in Creating, Manipulating and Parsing XML

An XML or extensible markup language is the universal language for any data on the web. If the HTML or Hypertext Markup Language is primarily concerned on a certain web page’s layout or look, the XML, however, is concerned on the site’s document structure and content. In other words, HTML can be somehow compared to a car’s outside design while XML can be compared to the car’s interior and the engine itself. And since XML isn’t a type of a fixed format like HTML (e.g. HTML is used only for web pages, DOC and DOCX for word, XLS or XLSX for excel, etc.), it can be used in other programs aside from web pages. Hence, the word Extensible was used as a part of its name.


Delphi in Creating, Manipulating and Parsing XML
Delphi in Creating, Manipulating and Parsing XML


If you’re a Delphi Programmer, it is a protocol that you must know how to use XML. By using Delphi’s TXmlDocument component, you can either read or construct an XML document.



Steps in Creating your Own XML Program

  1. Open Delphi (you must have the compiler installed in your PC) before constructing your XML document using AddChild method.


  1. Assign the resulting XML to a TStringList object. Use TStringList methods such as Insert or Add to put additional nodes and elements to your XML String. However, always remember that a valid XML must contain a <DOCTYPE …> and an <?xml …> element. Otherwise, Delphi won’t identify it as an XML program string.


  1. Save your newly-made XML contained in the string list into your file.


Be informed, however, that Delphi’s TXMLDocument component implementation, which uses Microsoft XML parser by default, does not provide an ‘add ntDocType’ option.