You can use a 4Suite InputSource to drive a SAX parser. This might be useful in cases where you are integrating domlette and SAX code, or perhaps for convenience, e.g. creating an InputSource from a string:
from xml.sax import * from xml.sax.handler import feature_namespaces from Ft.Xml import InputSource XML = "<grammar xmlns='http://relaxng.org/ns/structure/1.0' foo='bar'/>" parser = make_parser() parser.setFeature(feature_namespaces, 1) #Of course in reality you'd use your own specialized handlers parser.setContentHandler(ContentHandler()) factory = InputSource.DefaultFactory isrc = factory.fromString(XML, 'urn:dummy') parser.parse(isrc)
The URI we pass into fromString() is a URI for the XML document itself. It is there so it can be used as a base when resolving relative URI references such as might be found in a DOCTYPE or entity declaration. All documents that can utilize URI references, be they XML, HTML, XSLT, or whatever, require such a URI. It is a common misconception that the current working directory comes into play; it doesn't. Although 4Suite will generate a URI if there is none provided, and although there's no need for such resolution with our simple XML doc, we pass in a dummy URI anyway, to suppress a warning.
