com.hp.hpl.sparta
Class Node

java.lang.Object
  |
  +--com.hp.hpl.sparta.Node
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
Document, Element, Text

public abstract class Node
extends java.lang.Object
implements java.lang.Cloneable

An XML node.

Copyright (C) 2002 Hewlett-Packard Company. This file is part of Sparta, an XML Parser, DOM, and XPath library. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Version:
$Date: 2002/08/19 05:03:54 $ $Revision: 1.1.1.1 $
Author:
Eamonn O'Brien-Strain
See Also:
GNU Lesser General Public License

Constructor Summary
Node()
           
 
Method Summary
 java.lang.Object clone()
          Return a deep copy of this node.
 java.lang.Object getAnnotation()
           
 Node getNextSibling()
           
 Document getOwnerDocument()
          null IFF this is a Document
 Element getParentNode()
           
 Node getPreviousSibling()
           
protected static void htmlEncode(java.io.Writer writer, java.lang.String string)
          Quote special XML characters '<', '>', '&', '"' if necessary, and write to character stream.
 void setAnnotation(java.lang.Object annotation)
          Use by client to attach arbitrary data to DOM document.
 java.lang.String toString()
          Hierarchically concatenated text nodes.
 java.lang.String toXml()
           
 boolean xpathEnsure(java.lang.String xpath)
          Make sure this XPath exists, creating nodes if necessary, returning true if any nodes created.
abstract  Element xpathSelectElement(java.lang.String xpath)
          Select the first element that matches the relative XPath expression with respect to this node, or null if there is no match.
abstract  java.util.Enumeration xpathSelectElements(java.lang.String xpath)
          Select all the elements that match the relative XPath expression with respect to this node.
abstract  java.lang.String xpathSelectString(java.lang.String xpath)
          Select the first element that matches the relative XPath expression with respect to this node, or null if there is no match.
abstract  java.util.Enumeration xpathSelectStrings(java.lang.String xpath)
          Select all the strings that match the relative XPath expression with respect to this node.
 void xpathSetStrings(java.lang.String xpath, java.lang.String value)
          For an xpath expression of the form "xpathPrefix/@attrName" set the attribute "attrName" to attrValue on all elements that match "XpathPrefix" which is an arbitrary xpath expression matching elements, or for an xpath expression of the form "xpathPrefixe/text()" set the text of all matching text nodes.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Node

public Node()
Method Detail

getOwnerDocument

public Document getOwnerDocument()
null IFF this is a Document

getParentNode

public Element getParentNode()

getPreviousSibling

public Node getPreviousSibling()

getNextSibling

public Node getNextSibling()

getAnnotation

public java.lang.Object getAnnotation()

setAnnotation

public void setAnnotation(java.lang.Object annotation)
Use by client to attach arbitrary data to DOM document. Does not update indices and other observers.

toXml

public java.lang.String toXml()
                       throws java.io.IOException

xpathSetStrings

public void xpathSetStrings(java.lang.String xpath,
                            java.lang.String value)
                     throws ParseException
For an xpath expression of the form "xpathPrefix/@attrName" set the attribute "attrName" to attrValue on all elements that match "XpathPrefix" which is an arbitrary xpath expression matching elements, or for an xpath expression of the form "xpathPrefixe/text()" set the text of all matching text nodes. (The following doc is used in the examples below.)







  • node.xpathSetStrings( "xpathPrefix/@attrName", value ) is equivalent to
    foreach element in node.xpathSelectElement(xpathPrefix):
    element.setAttribute( "attrName", value );
    
  • doc.xpathSetStrings( "/a/b/@x", "rrr" ) will result in
    
    
    
    
    
    
    
    
    (Every matching child gets its attribute set.)
  • To set only the first child you would have to do doc.xpathSetStrings( "/a/b[@x]/@x", "rrr" ) which would result in:
    
    
    
    
    
    
    
    
  • Not matching calls silently do nothing.
  • doc.xpathSetStrings("/a/b/text()", "TTT" ) will result in:
    
    
    TTT
    TTT
    TTT
    
    
    
  • doc.xpathSetStrings("/a/text()", "TTT" ) will result in:
    
    TTT
    
    

xpathEnsure

public boolean xpathEnsure(java.lang.String xpath)
                    throws ParseException
Make sure this XPath exists, creating nodes if necessary, returning true if any nodes created. Xpath must of the type that returns an element (not a string).

xpathSelectElements

public abstract java.util.Enumeration xpathSelectElements(java.lang.String xpath)
                                                   throws ParseException
Select all the elements that match the relative XPath expression with respect to this node.

xpathSelectStrings

public abstract java.util.Enumeration xpathSelectStrings(java.lang.String xpath)
                                                  throws ParseException
Select all the strings that match the relative XPath expression with respect to this node.

xpathSelectElement

public abstract Element xpathSelectElement(java.lang.String xpath)
                                    throws ParseException
Select the first element that matches the relative XPath expression with respect to this node, or null if there is no match.

xpathSelectString

public abstract java.lang.String xpathSelectString(java.lang.String xpath)
                                            throws ParseException
Select the first element that matches the relative XPath expression with respect to this node, or null if there is no match.

clone

public java.lang.Object clone()
Return a deep copy of this node.
Overrides:
clone in class java.lang.Object

toString

public java.lang.String toString()
Hierarchically concatenated text nodes.
Overrides:
toString in class java.lang.Object

htmlEncode

protected static void htmlEncode(java.io.Writer writer,
                                 java.lang.String string)
                          throws java.io.IOException
Quote special XML characters '<', '>', '&', '"' if necessary, and write to character stream. We write to a character stream rather than simply returning a stream to avoid creating unneccessary objects.