xmldocument.java
来自「java jdk 1.4的源码」· Java 代码 · 共 1,456 行 · 第 1/4 页
JAVA
1,456 行
// and return the first (only!) doctype. for (int i = 0; true; i++) { Node n = item (i); if (n == null) return null; if (n instanceof DocumentType) return (DocumentType) n; } } /** * Establishes how the document prints its document type. If a system * ID (URI) is provided, that is used in a SYSTEM (or PUBLIC, if a public * ID is also provided) declaration. If an internal subset is provided, * that will be printed. The root element in the DTD will be what the * document itself provides. * * @param dtdPublicId Holds a "public identifier" used to identify the * last part of the external DTD subset that is read into the DTD. * This may be omitted, and in any case is ignored unless a system * ID is provided. * @param dtdSystemId Holds a "system identifier" (a URI) used to * identify the last part of the external DTD subset that is read * into the DTD. This may be omitted, in which case the document * type will contain at most an internal subset. This URI should * not be a relative URI unless the document will be accessed in a * context from which that relative URI makes sense. * @param internalSubset Optional; this holds XML text which will * be put into the internal subset. This must be legal syntax, * and it is not tested by this document. */ public DocumentType setDoctype ( String dtdPublicId, String dtdSystemId, String internalSubset ) { Doctype retval = (Doctype) getDoctype (); if (retval != null) retval.setPrintInfo (dtdPublicId, dtdSystemId, internalSubset); else { retval = new Doctype (dtdPublicId, dtdSystemId, internalSubset); retval.setOwnerDocument (this); insertBefore (retval, getFirstChild ()); } return retval; } /** * DOM: Returns the content root element. */ public Element getDocumentElement () { // We ignore comments, PIs, whitespace, etc // and return the first (only!) element. for (int i = 0; true; i++) { Node n = item (i); if (n == null) return null; if (n instanceof Element) { return (Element)n; } } } /** * Assigns the element factory to be used by this document. * * @param factory the element factory to be used; if this is null, * all elements will be implemented by <em>ElementNode</em>. * @deprecated */ final public void setElementFactory (ElementFactory factory) { this.factory = factory; } /** * Returns the element factory to be used by this document. * @deprecated */ final public ElementFactory getElementFactory () { return factory; } /** * DOM: Create a new element, associated with this document, with * no children, attributes, or parent, by calling createElementEx. * * @param tagName the tag of the element, used to determine what * type element to create as well as what tag to assign the new node. * @exception IllegalArgumentException if a mapping is defined, * but is invalid because the element can't be instantiated or * does not subclass <em>ElementNode</em>. */ public Element createElement(String tagName) throws DOMException { return createElementEx (tagName); } /** * <b>DOM2:</b> * @since DOM Level 2 * Warning: Does not work with the deprecated ElementFactory */ public Element createElementNS(String namespaceURI, String qualifiedName) throws DOMException { // Check arguments and throw appropriate exceptions ElementNode2.checkArguments(namespaceURI, qualifiedName); ElementNode2 retval = new ElementNode2(namespaceURI, qualifiedName); retval.setOwnerDocument(this); return retval; } /** * Create a new element, associated with this document, with no * children, attributes, or parent. This uses the element factory, * or else directly constructs an ElementNode. * * @param tagName the tag of the element, used to determine what * type element to create as well as what tag to assign the new node. * @exception IllegalArgumentException if a mapping is defined, * but is invalid because the element can't be instantiated or * does not subclass <em>ElementNode</em>. * @deprecated Use the standard method createElement instead */ final public ElementEx createElementEx(String tagName) throws DOMException { ElementNode retval; if (!XmlNames.isName (tagName)) { throw new DomEx (DomEx.INVALID_CHARACTER_ERR); } if (factory != null) { // Ask factory to create appropriate ElementNode subtype retval = (ElementNode) factory.createElementEx(tagName); // Set the name of the ElementNode retval.setTag(tagName); } else { retval = new ElementNode(tagName); } retval.setOwnerDocument(this); return retval; } /** * Create a new element, associated with this document, with no * children, attributes, or parent. This uses the element factory, * or else directly constructs an ElementNode. * * @param uri The namespace used to determine what type of element to * create. This is not stored with the element; the element must be * inserted into a DOM tree in a location where namespace declarations * cause its tag to be interpreted correctly. * @param tagName The tag of the element, which should not contain * any namespace prefix. * @exception IllegalArgumentException When a mapping is defined, * but is invalid because the element can't be instantiated or * does not subclass <em>ElementNode</em>. * @deprecated Use the standard method createElementNS instead */ final public ElementEx createElementEx(String uri, String tagName) throws DOMException { ElementNode retval; if (!XmlNames.isName(tagName)) { throw new DomEx (DomEx.INVALID_CHARACTER_ERR); } if (factory != null) { // Ask factory to create appropriate ElementNode subtype retval = (ElementNode) factory.createElementEx(uri, tagName); // Set the name of the ElementNode retval.setTag(tagName); } else { retval = new ElementNode(tagName); } retval.setOwnerDocument(this); return retval; } /** * DOM: returns a Text node initialized with the given text. * * @param text The contents of the text node being created, which * should never contain "<em>]]></em>". */ public Text createTextNode (String text) { TextNode retval; retval = new TextNode (); retval.setOwnerDocument (this); if (text != null) retval.setText (text.toCharArray ()); return retval; } /** * DOM: Returns a CDATA section initialized with the given text. * * @param text the text which the CDATA section will hold, which * should never contain "<em>]]></em>". */ public CDATASection createCDATASection (String text) { CDataNode retval = new CDataNode (); if (text != null) retval.setText (text.toCharArray ()); retval.setOwnerDocument (this); return retval; } // package private ... convenience rtn, reduced mallocation TextNode newText (char buf [], int offset, int len) throws SAXException { TextNode retval = (TextNode) createTextNode (null); char data [] = new char [len]; System.arraycopy (buf, offset, data, 0, len); retval.setText (data); return retval; } /** * DOM: Returns a Processing Instruction node for the specified * processing target, with the given instructions. * * @param target the target of the processing instruction * @param instructions the processing instruction, which should * never contain "<em>?></em>". */ public ProcessingInstruction createProcessingInstruction ( String target, String instructions ) throws DOMException { if (!XmlNames.isName (target)) throw new DomEx (DomEx.INVALID_CHARACTER_ERR); PINode retval = new PINode (target, instructions); retval.setOwnerDocument (this); return retval; } /** * DOM: Returns a valueless attribute node with no default value. * * @param name the name of the attribute. */ public Attr createAttribute(String name) throws DOMException { if (!XmlNames.isName(name)) { throw new DomEx(DOMException.INVALID_CHARACTER_ERR); } AttributeNode1 retval = new AttributeNode1(name, "", true, null); retval.setOwnerDocument(this); return retval; } /** * <b>DOM2:</b> * @since DOM Level 2 */ public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException { AttributeNode.checkArguments(namespaceURI, qualifiedName); AttributeNode retval = new AttributeNode(namespaceURI, qualifiedName, "", true, null); retval.setOwnerDocument(this); return retval; } /** * DOM: creates a comment node. * * @param data The characters which will be in the comment. * This should not include the "<em>--</em>" characters. */ public Comment createComment (String data) { CommentNode retval = new CommentNode (data); retval.setOwnerDocument (this); return retval; } /** DOM: returns null. */ public Document getOwnerDoc () { return null; } /** * The <code>DOMImplementation</code> object that handles this document. */ public DOMImplementation getImplementation() { return DOMImplementationImpl.getDOMImplementation(); } /** * DOM: Creates a new document fragment. */ public DocumentFragment createDocumentFragment () { DocFragNode retval = new DocFragNode (); retval.setOwnerDocument (this); return retval; } /** * DOM: Creates an entity reference to the named entity. * Note that the entity must already be defined in the document * type, and that the name must be a legal entity name. * * @param name the name of the the parsed entity */ public EntityReference createEntityReference (String name) throws DOMException { if (!XmlNames.isName (name)) throw new DomEx (DomEx.INVALID_CHARACTER_ERR); EntityRefNode retval = new EntityRefNode (name); retval.setOwnerDocument (this); return retval; } /** DOM: Returns the string "#document". */ final public String getNodeName () { return "#document"; } /** * DOM: Returns a copy of this document. * * <P> <em>Note:</em> At this time, any element factory or document * type associated with this document will not be cloned. * * @param deep if true, child nodes are also cloned. */ public Node cloneNode (boolean deep) { XmlDocument retval = new XmlDocument (); retval.systemId = systemId; // XXX clone the element factory ... if (deep) {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?