xml.dom.xhtml
Class XhtmlDomDocument

java.lang.Object
  |
  +--xml.dom.DomNode
        |
        +--xml.dom.DomDocument
              |
              +--xml.dom.xhtml.XhtmlDomDocument
All Implemented Interfaces:
java.lang.Cloneable, Document, DocumentEvent, DocumentTraversal, EventTarget, HTMLDocument, Node, NodeList

public class XhtmlDomDocument
extends DomDocument
implements HTMLDocument

XHTML subclass of "DomDocument", supporting the HTML DOM interfaces that make the most sense in the XHTML world.

This is basically just an XML DOM which does a little bit of error checking for nodes in the XHTML namespace. It doesn't support many of the HTML DOM custom element subclasses, and while it enforces case in some ways, it does so using the XHTML rules not those of the HTML DOM. In short, it's an XML DOM that you can safely use anywhere, but it has some added intelligence about the XHTML namespace, as well as basic HTML DOM support.

Note that a number of the HTMLDocument methods are not implemented, and invoking them will cause a DOMException to be thrown. These include all methods returning HTMLCollection objects, which are superfluous since the L2 iterators can do the same things more generically. They also include the methods which require interaction with a parser, since those exist primarily to support JavaScript code that writes literal HTML text to the parser, instead of supporting generally useful functionality such as loading a document given its URI.

Version:
$Date: 2000/07/15 00:58:13 $
Author:
David Brownell

Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
  XhtmlDomDocument()
          Constructs a Document node, associating it with an instance of the XhtmlDomImpl class.
protected XhtmlDomDocument(XhtmlDomImpl impl)
          Constructs a Document node, associating it with the specified XhtmlDomImpl instance.
 
Method Summary
 void close()
          Closes a document stream opened by open() and forces rendering.
 Attr createAttributeNS(java.lang.String namespaceURI, java.lang.String name)
          DOM L2 Returns a newly created attribute with the specified name and namespace information.
 Element createElementNS(java.lang.String namespaceURI, java.lang.String name)
          DOM L2 Returns a newly created element with the specified name and namespace information; if this is the XHTML namespace, it requires that the name be an XHTML name (after any prefix is removed)
 HTMLCollection getAnchors()
          A collection of all the anchor (A ) elements in a document with a value for the name attribute.
 HTMLCollection getApplets()
          A collection of all the OBJECT elements that include applets and APPLET ( deprecated ) elements in a document.
 HTMLElement getBody()
          DOM L1 (HTML) Returns the first "body" or "frameset" element in the document.
 java.lang.String getCookie()
          The cookies associated with this document.
 java.lang.String getDomain()
          The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
 Element getElementById(java.lang.String id)
          DOM L1 (HTML) Returns the element with the specified "id" attribute.
 NodeList getElementsByName(java.lang.String name)
          DOM L1 (HTML) Same as the getElementsByTagname () method.
 HTMLCollection getForms()
          A collection of all the forms of a document.
 HTMLCollection getImages()
          A collection of all the IMG elements in a document.
 HTMLCollection getLinks()
          A collection of all AREA elements and anchor ( A ) elements in a document with a value for the href attribute.
 java.lang.String getReferrer()
          Returns the URI of the page that linked to this page.
 java.lang.String getTitle()
          The title of a document as specified by the TITLE element in the head of the document.
 java.lang.String getURL()
          The complete URI of the document.
 void open()
          Note.
 void setBody(HTMLElement body)
           
 void setCookie(java.lang.String cookies)
           
 void setTitle(java.lang.String title)
           
 void write(java.lang.String xhtmlText)
          Write a string of text to a document stream opened by open() .
 void writeln(java.lang.String xhtmlText)
          Write a string of text followed by a newline character to a document stream opened by open() .
 
Methods inherited from class xml.dom.DomDocument
appendChild, createAttribute, createCDATASection, createComment, createDocumentFragment, createElement, createEntityReference, createNodeIterator, createProcessingInstruction, createTextNode, createTreeWalker, getDoctype, getDocumentElement, getImplementation, getNodeName, importNode, insertBefore, isCheckingCharacters, replaceChild, setCheckingCharacters, verifyXmlName
 
Methods inherited from class xml.dom.DomNode
addEventListener, clone, cloneNode, createEvent, dispatchEvent, getAttributes, getChildNodes, getElementsByTagName, getElementsByTagNameNS, getFirstChild, getLastChild, getLength, getLocalName, getNamespaceURI, getNextSibling, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, isReadonly, isSupported, item, makeReadonly, nameAndTypeEquals, normalize, removeChild, removeEventListener, setNodeValue, setPrefix, trimToSize
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Document
createAttribute, createCDATASection, createComment, createDocumentFragment, createElement, createEntityReference, createProcessingInstruction, createTextNode, getDoctype, getDocumentElement, getElementsByTagName, getElementsByTagNameNS, getImplementation, importNode
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, getAttributes, getChildNodes, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, hasAttributes, hasChildNodes, insertBefore, isSupported, normalize, removeChild, replaceChild, setNodeValue, setPrefix
 

Constructor Detail

XhtmlDomDocument

public XhtmlDomDocument()
Constructs a Document node, associating it with an instance of the XhtmlDomImpl class.
See Also:
XhtmlDomImpl

XhtmlDomDocument

protected XhtmlDomDocument(XhtmlDomImpl impl)
Constructs a Document node, associating it with the specified XhtmlDomImpl instance.
Method Detail

createAttributeNS

public Attr createAttributeNS(java.lang.String namespaceURI,
                              java.lang.String name)
DOM L2 Returns a newly created attribute with the specified name and namespace information.
Specified by:
createAttributeNS in interface Document
Overrides:
createAttributeNS in class DomDocument
Following copied from interface: org.w3c.dom.Document
Parameters:
namespaceURIThe - namespace URI of the attribute to create.
qualifiedNameThe - qualified name of the attribute to instantiate.
Returns:
A new Attr object with the following attributes: AttributeValueNode.nodeNamequalifiedName Node.namespaceURInamespaceURI Node.prefixprefix, extracted from qualifiedName, or null if there is no prefixNode.localNamelocal name, extracted from qualifiedNameAttr.name qualifiedNameNode.nodeValuethe empty string
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace", or if the qualifiedName is "xmlns" and the namespaceURI is different from " http://www.w3.org/2000/xmlns/".

createElementNS

public Element createElementNS(java.lang.String namespaceURI,
                               java.lang.String name)
DOM L2 Returns a newly created element with the specified name and namespace information; if this is the XHTML namespace, it requires that the name be an XHTML name (after any prefix is removed)
Specified by:
createElementNS in interface Document
Overrides:
createElementNS in class DomDocument
Following copied from interface: org.w3c.dom.Document
Parameters:
namespaceURIThe - namespace URI of the element to create.
qualifiedNameThe - qualified name of the element type to instantiate.
Returns:
A new Element object with the following attributes:AttributeValueNode.nodeName qualifiedNameNode.namespaceURI namespaceURINode.prefixprefix, extracted from qualifiedName, or null if there is no prefixNode.localNamelocal name, extracted from qualifiedNameElement.tagName qualifiedName
Throws:
DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name contains an illegal character.
NAMESPACE_ERR: Raised if the qualifiedName is malformed, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from " http://www.w3.org/XML/1998/namespace" .

getBody

public HTMLElement getBody()
DOM L1 (HTML) Returns the first "body" or "frameset" element in the document.
Specified by:
getBody in interface HTMLDocument

setBody

public void setBody(HTMLElement body)
Specified by:
setBody in interface HTMLDocument

getTitle

public java.lang.String getTitle()
Description copied from interface: HTMLDocument
The title of a document as specified by the TITLE element in the head of the document.
Specified by:
getTitle in interface HTMLDocument

setTitle

public void setTitle(java.lang.String title)
Specified by:
setTitle in interface HTMLDocument

getElementById

public Element getElementById(java.lang.String id)
DOM L1 (HTML) Returns the element with the specified "id" attribute. If there is no such element, and an element permitted to have a "name" attribute has a matching value, returns that element.
Specified by:
getElementById in interface Document
Overrides:
getElementById in class DomDocument
Following copied from interface: org.w3c.dom.Document
Parameters:
elementIdThe - unique id value for an element.
Returns:
The matching element.

getElementsByName

public NodeList getElementsByName(java.lang.String name)
DOM L1 (HTML) Same as the getElementsByTagname () method.
Specified by:
getElementsByName in interface HTMLDocument
Following copied from interface: org.w3c.dom.html.HTMLDocument
Parameters:
elementName - The name attribute value for an element.
Returns:
The matching elements.

getCookie

public java.lang.String getCookie()
Description copied from interface: HTMLDocument
The cookies associated with this document. If there are none, the value is an empty string. Otherwise, the value is a string: a semicolon-delimited list of "name, value" pairs for all the cookies associated with the page. For example, name=value;expires=date .
Specified by:
getCookie in interface HTMLDocument

setCookie

public void setCookie(java.lang.String cookies)
Specified by:
setCookie in interface HTMLDocument

getDomain

public java.lang.String getDomain()
Description copied from interface: HTMLDocument
The domain name of the server that served the document, or null if the server cannot be identified by a domain name.
Specified by:
getDomain in interface HTMLDocument

getReferrer

public java.lang.String getReferrer()
Description copied from interface: HTMLDocument
Returns the URI of the page that linked to this page. The value is an empty string if the user navigated to the page directly (not through a link, but, for example, via a bookmark).
Specified by:
getReferrer in interface HTMLDocument

getURL

public java.lang.String getURL()
Description copied from interface: HTMLDocument
The complete URI of the document.
Specified by:
getURL in interface HTMLDocument

open

public void open()
Description copied from interface: HTMLDocument
Note. This method and the ones following allow a user to add to or replace the structure model of a document using strings of unparsed HTML. At the time of writing alternate methods for providing similar functionality for both HTML and XML documents were being considered. The following methods may be deprecated at some point in the future in favor of a more general-purpose mechanism.
Open a document stream for writing. If a document exists in the target, this method clears it.
Specified by:
open in interface HTMLDocument

close

public void close()
Description copied from interface: HTMLDocument
Closes a document stream opened by open() and forces rendering.
Specified by:
close in interface HTMLDocument

write

public void write(java.lang.String xhtmlText)
Description copied from interface: HTMLDocument
Write a string of text to a document stream opened by open() . The text is parsed into the document's structure model.
Specified by:
write in interface HTMLDocument
Following copied from interface: org.w3c.dom.html.HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structure model.

writeln

public void writeln(java.lang.String xhtmlText)
Description copied from interface: HTMLDocument
Write a string of text followed by a newline character to a document stream opened by open() . The text is parsed into the document's structure model.
Specified by:
writeln in interface HTMLDocument
Following copied from interface: org.w3c.dom.html.HTMLDocument
Parameters:
text - The string to be parsed into some structure in the document structure model.

getAnchors

public HTMLCollection getAnchors()
Description copied from interface: HTMLDocument
A collection of all the anchor (A ) elements in a document with a value for the name attribute. Note. For reasons of backwards compatibility, the returned set of anchors only contains those anchors created with the name attribute, not those created with the id attribute.
Specified by:
getAnchors in interface HTMLDocument

getApplets

public HTMLCollection getApplets()
Description copied from interface: HTMLDocument
A collection of all the OBJECT elements that include applets and APPLET ( deprecated ) elements in a document.
Specified by:
getApplets in interface HTMLDocument

getForms

public HTMLCollection getForms()
Description copied from interface: HTMLDocument
A collection of all the forms of a document.
Specified by:
getForms in interface HTMLDocument

getImages

public HTMLCollection getImages()
Description copied from interface: HTMLDocument
A collection of all the IMG elements in a document. The behavior is limited to IMG elements for backwards compatibility.
Specified by:
getImages in interface HTMLDocument

getLinks

public HTMLCollection getLinks()
Description copied from interface: HTMLDocument
A collection of all AREA elements and anchor ( A ) elements in a document with a value for the href attribute.
Specified by:
getLinks in interface HTMLDocument

Source code is GPL'd at http://xmlconf.sourceforge.net.