XmlParser

Standard:

XML related implementations:

XML editing environments:

xml.el

This parser by EmmanuelBriot? is part of Gnus and part of Emacs 21.

Here’s a link to the file in Emacs’s sources:

See also XmlParserExamples.

xml-parse.el

This parser by JohnWiegley is available from his homepage. It is probably deprecated. The data structure returned looks very much like the one returned by xml.el, but element names are strings instead of symbols. On the other hand, it contains additional code to pretty-print the xml data structures such that it can be used as an XML indentation fix.

You can get the source from here:

dom.el

The XML parsers will create a lisp data structure for you and they both provide access methods to the structure. Neither of the two provides the DOM interface, however. Here comes the DOM implementation in dom.el – you feed it the result of xml.el and then you can use the DOM interface functions.

You can get the source from here:

Related Links:

xpath.el

If you work with a DOM, a lot of the work you will be doing involves finding nodes in the document tree. Instead of looping through it yourself, writing lots of awkward and brittle code, you could use XPATH to do this for you. XPATH allows you to use path-like strings to specify nodes.

The following code, for example, reads an XML file, creates a DOM, and uses an XPATH to find chapter titles.

    (let* ((data (car (xml-parse-file "sample.xml")))
           (doc (dom-make-document-from-xml data)))
      (xpath-resolve (dom-document-element doc)
                     "descendant::chapter/child::title"))

You can get the source from here:

This requires partial (or full) installation of CEDET (see below), as well as:

To use xpath.el you need Wisent, a Bison-like parser generator in Elisp. Wisent is part of the Semantic package (see: SemanticBovinator), but as far as I can see it is not in the released version of Semantic. You can get it along with the entire CEDET beta tar-ball: http://sourceforge.net/project/showfiles.php?group_id=17886&release_id=192965

As far as I can see, you need only these three files:

If your Emacs version already has CEDET pre-packaged with it (e.g., 23.3), xpath-parser.el may be edited to require the correct symbols to take advantage of the pre-packaged Wisent:

  1. Go to your Emacs Lisp directory (e.g., <Emacs installation directory>\lisp in Windows).
  2. Look for the Wisent package in the CEDET package (e.g., <Emacs installation directory>\lisp\cedet\semantic\wisent).
  3. Look for and open the file where wisent-parse is defined.
  4. Note that file’s provide line (e.g., (provide ‘semantic/wisent/wisent)).
  5. Look for and open the file where wisent-compile-grammar is defined.
  6. Note that file’s provide line (e.g., (provide ‘semantic/wisent/comp)).
  7. Edit xpath-parser.el so that the correct provided symbols are required (e.g., (require ‘semantic/wisent/wisent) and (require ‘semantic/wisent/comp) instead of ‘wisent and ‘wisent-comp)).

Note that most of the xpath-parser is generated by a BNF file:

The xpath-parser requires wisent, which is part of the SemanticBovinator (CVS only, at the end of 2001).

Uh, oh! I modified the s-expr grammar in xpath-parser.el without being aware of this … :-/ – OliverScholz

Related links:

xslt.el

XSLT and XPATH together make an XSL engine. XEmacs comes with xslide and xslt-process.

Related links:


CategoryCode CategoryXML CategoryExtensions CategoryData