Gem #21: How to parse an XML text Author: Emmanuel Briot, Senior Software Engineer, AdaCore Abstract: Ada Gem #21 The World Wide Web Consortium (W3C) develops various specifications around the XML file format. In particular, it specifies various APIs to load, process and write an XML file. Although these APIs are not specified for Ada, XML/Ada tries to conform as closely as possible to them. This gem describes how to use XML/Ada to parse an XML file. Let s get started ¦ There are two main APIs to parse an XML file. One (the Document Object Model, DOM) reads the file and generates a tree in memory representing the whole document. Typically, because of the amount of operations mandated by the specifications, this tree is several times larger than the document itself, and thus depending on the amount of memory on your machine, it might limit the size of documents your application can read. On the other hand, it provides a lot of flexibility in the handling of these trees. The other method (SAX) is based on callbacks, which are called when various constructs are seen while reading the XML file. This requires almost no memory, but
/lp/association-for-computing-machinery/gem-21-how-to-parse-an-xml-text-lx69elRuDq