
com.sun.msv.generator.DOM2toSAX2 Maven / Gradle / Ivy
package com.sun.msv.generator;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
public class DOM2toSAX2 {
public DOM2toSAX2() {}
private static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
protected ContentHandler handler;
public void setContentHandler( ContentHandler handler ) {
this.handler = handler;
}
public ContentHandler getContentHandler() {
return this.handler;
}
public void traverse(Document dom) throws SAXException {
if(handler==null)
throw new IllegalArgumentException("content handler is not set");
handler.startDocument();
onElement(dom.getDocumentElement());
handler.endDocument();
}
/** converts DOM attributes into SAX attributes. */
protected Attributes convertAttributes( Element e ) {
NamedNodeMap atts = e.getAttributes();
AttributesImpl sa = new AttributesImpl();
for( int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy