11.14. Using PYX as a DOM Data Source

Here is a utility that allows PYX notation to act as a data source for DOM.

 CD-ROM reference=11020.txt """ DOM builder from PYX notation source """ from string import * from StringIO import StringIO from xml.dom.builder import Builder class pyxBuilder(Builder): def __init__(self): Builder.__init__(self) def decode(self,s): # Convert PYX escaped newlines to real newlines. return join (split (s,r"\n"),"\n") def feed(self, data): self.feedpyx(StringIO(data)) def feedpyx(self, pyxStream): pyx = pyxStream.readline() while pyx != "": if pyx[0] == "(": elementname = pyx[1:-1] pyx = pyxStream.readline() dict={} while pyx[0] == "A": [name,value] = split(pyx[1:-1], " ", 1) dict[name] = self.decode(value) pyx = pyxStream.readline() ...

Get XML Processing with Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.