org.w3c.dom.DocumentType#getOwnerDocument ( )源码实例Demo

下面列出了org.w3c.dom.DocumentType#getOwnerDocument ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Bytecoder   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = createDocument(doctype);
        // If namespaceURI and qualifiedName are null return a Document with no document element.
        if (qualifiedName != null || namespaceURI != null) {
            Element e = doc.createElementNS(namespaceURI, qualifiedName);
            doc.appendChild(e);
        }
        return doc;
}
 
源代码2 项目: caja   文件: Nodes.java
/**
 * Returns a rendering of document type.  This is handled explicitly here
 * rather than in {@link Nodes#render(Node, MarkupRenderMode)} to avoid
 * rendering a document type in the middle of a document.
 *
 * @return null if nothing to render or docType is invalid.
 */
private static @Nullable String renderDocumentType(DocumentType docType) {
  String publicId = docType.getPublicId();
  String systemId = docType.getSystemId();
  String nodeName;

  if (null != docType.getOwnerDocument() &&
      null != docType.getOwnerDocument().getDocumentElement() &&
      null != docType.getOwnerDocument().getDocumentElement().getNodeName()) {
    nodeName = docType.getOwnerDocument()
      .getDocumentElement()
      .getNodeName();
  } else {
    return null;
  }

  if (!DoctypeMaker.isHtml(nodeName, publicId, systemId)) {
    return null;
  }

  StringBuilder sb = new StringBuilder();
  sb.append("<!DOCTYPE ").append(nodeName);
  // The Name in the document type declaration must match the element type
  // of the root element.
  if (null != publicId && publicId.length() > 0) {
    sb.append(" PUBLIC ")
      .append('"')
      .append(publicId.replaceAll("\"", "%22"))
      .append('"');
  }
  if (null != systemId && systemId.length() > 0) {
    // Sanity check - system urls should parse as an absolute uris
    try {
      URI u = new URI(systemId);
      if (u.isAbsolute() &&
          ("http".equals(u.getScheme()) || "https".equals(u.getScheme()))) {
        sb.append(" ")
          .append('"')
          .append(systemId.replaceAll("\"", "%22"))
          .append('"');
      }
    } catch (URISyntaxException e) {
      return null;
    }
  }
  sb.append(">");
  return sb.toString();
}
 
源代码3 项目: hottub   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码5 项目: TencentKona-8   文件: DOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else if (doctype != null && doctype.getOwnerDocument() != null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码6 项目: TencentKona-8   文件: PSVIDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码7 项目: TencentKona-8   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
源代码8 项目: openjdk-8   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
源代码9 项目: hottub   文件: DOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else if (doctype != null && doctype.getOwnerDocument() != null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码10 项目: jdk8u60   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
源代码11 项目: JDKSourceCode1.8   文件: DOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else if (doctype != null && doctype.getOwnerDocument() != null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码13 项目: openjdk-8   文件: PSVIDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
源代码14 项目: openjdk-jdk9   文件: CoreDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
源代码15 项目: openjdk-jdk8u   文件: PSVIDOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else if (doctype != null && doctype.getOwnerDocument() != null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if (doctype != null && doctype.getOwnerDocument() != null) {
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
                               DOMMessageFormatter.formatMessage(
                               DOMMessageFormatter.XML_DOMAIN,
                                                   "WRONG_DOCUMENT_ERR", null));
    }
    DocumentImpl doc = new PSVIDocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}
 
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document createDocument(
        String namespaceURI,
        String qualifiedName,
        DocumentType doctype)
        throws DOMException {
        if (doctype != null && doctype.getOwnerDocument() != null) {
                String msg =
                        DOMMessageFormatter.formatMessage(
                                DOMMessageFormatter.DOM_DOMAIN,
                                "WRONG_DOCUMENT_ERR",
                                null);
                throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
        }
        CoreDocumentImpl doc = new CoreDocumentImpl(doctype);
        Element e = doc.createElementNS(namespaceURI, qualifiedName);
        doc.appendChild(e);
        return doc;
}
 
源代码20 项目: Bytecoder   文件: DOMImplementationImpl.java
/**
 * Introduced in DOM Level 2. <p>
 *
 * Creates an XML Document object of the specified type with its document
 * element.
 *
 * @param namespaceURI     The namespace URI of the document
 *                         element to create, or null.
 * @param qualifiedName    The qualified name of the document
 *                         element to create.
 * @param doctype          The type of document to be created or null.<p>
 *
 *                         When doctype is not null, its
 *                         Node.ownerDocument attribute is set to
 *                         the document being created.
 * @return Document        A new Document object.
 * @throws DOMException    WRONG_DOCUMENT_ERR: Raised if doctype has
 *                         already been used with a different document.
 * @since WD-DOM-Level-2-19990923
 */
public Document           createDocument(String namespaceURI,
                                         String qualifiedName,
                                         DocumentType doctype)
                                         throws DOMException
{
    if(namespaceURI == null && qualifiedName == null && doctype == null){
    //if namespaceURI, qualifiedName and doctype are null, returned document is empty with
    //no document element
        return new DocumentImpl();
    }
    else if (doctype != null && doctype.getOwnerDocument() != null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
        throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
    }
    DocumentImpl doc = new DocumentImpl(doctype);
    Element e = doc.createElementNS( namespaceURI, qualifiedName);
    doc.appendChild(e);
    return doc;
}