Parser Module

Abstract

The xml2rfc parser module contains two classes for public use: XmlRfcParser and XmlRfc.

XmlRfcParser is a basic XML parser which uses the lxml library to parse an xml file into a tree structure. An instance of XmlRfc contains a reference to this parsed tree, along with some helper methods to provide useful additional formatting to the tree.

Accessing nodes in the tree is done through the standard lxml.etree interface. You can read more about that at the lxml documentation

Example – getting the title of an rfc document:

root = xmlrfc.getroot()
title = root.find('front/title').text

Classes

class xml2rfc.parser.XmlRfcParser(source, verbose=False, quiet=False, cache_path=None, templates_path=None, library_dirs=None, network_loc='http://xml.resource.org/public/rfc/')

XML parser with callbacks to construct an RFC tree

parse(remove_comments=True, remove_pis=False)

Parses the source XML file and returns an XmlRfc instance

class xml2rfc.parser.XmlRfc(tree, default_dtd_path)

Internal representation of an RFC document

Contains an lxml.etree.ElementTree, with some additional helper methods to prepare the tree for output.

Accessing the rfc tree is done by getting the root node from getroot()

getpis()

Returns a list of the XML processing instructions

getroot()

Wrapper method to get the root of the XML tree

parse_pi(pi)

Add a processing instruction to the current state

Will also return the dictionary containing the added instructions for use in things like ?include instructions

replaceUnicode()

Traverses the RFC tree and replaces unicode characters with the proper equivalents specified in rfc2629-xhtml.ent.

Writers should call this method if the entire RFC document needs to be ascii formatted

validate(dtd_path=None)

Validate the document with its default dtd, or an optional one

Return a success bool along with a list of any errors

class xml2rfc.parser.XmlRfcError(msg, line_no=0)

Application XML errors with positional information

This class attempts to mirror the API of lxml’s error class

Table Of Contents

Previous topic

Graphical Appplication

Next topic

Writer Module

This Page