Thomas DeWeese <[EMAIL PROTECTED]> writes: > K. Ari Krupnikov wrote: > > > Is there a class that can accept SAX events and create a > > Batik DOM based on them? > > You will need to do some work but > batik.dom.svg.SAXSVGDocumentFactory acts as a content handler and > builds an SVGDocument. It's constructors don't let you do quite > what you want but if you subclass I think you could make it work.
Subclassing it is indeed not difficult, the only thing you need to do is expose the protected Document that it's building (declared in org.apache.batik.dom.util.SAXDocumentFactory). I did that and ran some tests using the default XMLReader you get from the JAXP SAXParserFactory. It seems that SAXSVGDocumentFactory requires http://xml.org/sax/features/namespace-prefixes to be set to true on the reader, otherwise it builds SVG elements that have a prefix ("svg:*") as org.apache.batik.dom.GenericElement, which causes a ClassCastException when Transcoder calls SVGOMDocument.getRootElement; SVG elements that don't have a prefix (assuming xmlns="http://www.w3.org/2000/svg") are correctly constructed as SVGSVGElement's. Calling setNamespaceAware(false) on SAXParserFactory also causes SAXSVGDocumentFactory to construct SVGSVGElement's. Is the factory ignoring startPrefixMapping() callbacks and doing its own namespace management based on qnames and xmlns:* attributes? In my real application, I will be using a class that is not an XMLReader and is not as controllable. In particular, I can't control if the class reports xmlns:* attributes (and I can't blame it for that, since SAX only requires readers to be able to set namespace-prefixes to false). Is there a way to make the SVG factory work when namespace-prefixes is false? Ari. Environment: Batik 1.5.1 Sun JDK 1.4.2_03-b02 on Linux XMLReader: JAXP default org.apache.xerces.parsers.SAXParser -- Elections only count as free and trials as fair if you can lose money betting on the outcome. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]