com.sun.msv.util.xml.DOMBuilder Maven / Gradle / Ivy
/*
* @(#)$Id: DOMBuilder.java,v 1.4 2003/06/09 20:37:41 kk122374 Exp $
*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
package com.sun.msv.util.xml;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;
/**
* builds DOM from SAX2 event stream.
*
* @author
* Kohsuke KAWAGUCHI
*/
public class DOMBuilder extends DefaultHandler {
private final Document dom;
private Node parent;
public DOMBuilder( Document document ) {
this.dom = document;
parent = dom;
}
public DOMBuilder() throws ParserConfigurationException {
this( DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() );
}
/**
* returns DOM. This method should be called after the parsing was completed.
*/
public Document getDocument() {
return dom;
}
public void startElement( String ns, String local, String qname, Attributes atts ) {
Element e = dom.createElementNS( ns, qname );
parent.appendChild(e);
parent = e;
for( int i=0; i © 2015 - 2025 Weber Informatics LLC | Privacy Policy