Example #1
0
  /** Creates an OMElement with the builder. */
  public OMElement createOMElement(
      String localName, OMNamespace ns, OMContainer parent, OMXMLParserWrapper builder) {
    switch (((ParentNode) parent).getNodeType()) {
      case Node.ELEMENT_NODE: // We are adding a new child to an elem
        ElementImpl parentElem = (ElementImpl) parent;
        ElementImpl elem =
            new ElementImpl(
                (DocumentImpl) parentElem.getOwnerDocument(),
                localName,
                (NamespaceImpl) ns,
                builder,
                this);
        parentElem.appendChild(elem);
        return elem;
      case Node.DOCUMENT_NODE:
        DocumentImpl docImpl = (DocumentImpl) parent;
        ElementImpl elem2 = new ElementImpl(docImpl, localName, (NamespaceImpl) ns, builder, this);
        docImpl.appendChild(elem2);
        return elem2;

      case Node.DOCUMENT_FRAGMENT_NODE:
        DocumentFragmentImpl docFragImpl = (DocumentFragmentImpl) parent;
        return new ElementImpl(
            (DocumentImpl) docFragImpl.getOwnerDocument(),
            localName,
            (NamespaceImpl) ns,
            builder,
            this);
      default:
        throw new OMDOMException(
            "The parent container can only be an ELEMENT, DOCUMENT " + "or a DOCUMENT FRAGMENT");
    }
  }
 public Document parse(InputSource inputSource) throws SAXException, IOException {
   try {
     OMDOMFactory factory = new OMDOMFactory();
     // Not really sure whether this will work :-?
     XMLStreamReader reader = StAXUtils.createXMLStreamReader(inputSource.getCharacterStream());
     StAXOMBuilder builder = new StAXOMBuilder(factory, reader);
     DocumentImpl doc = (DocumentImpl) builder.getDocument();
     ((ElementImpl) doc.getDocumentElement()).build();
     return (DocumentImpl) builder.getDocument();
   } catch (XMLStreamException e) {
     throw new SAXException(e);
   }
 }
 /**
  * Returns a new document impl.
  *
  * @see javax.xml.parsers.DocumentBuilder#newDocument()
  */
 public Document newDocument() {
   OMDOMFactory factory = new OMDOMFactory();
   DocumentImpl documentImpl = new DocumentImpl(factory);
   documentImpl.setComplete(true);
   return documentImpl;
 }