org.objectweb.xml.util
Class XElement

java.lang.Object
  |
  +--org.objectweb.xml.util.XElement

public class XElement
extends Object


Constructor Summary
XElement()
           
XElement(String name)
           
XElement(String name, String value)
           
 
Method Summary
 void addAttribute(String attname, String attval)
          Add an attribute to this XML element
 boolean addElement(String elname, String val)
          Add an element to the XML tree according to a "path/name" string.
 boolean addElement(String path, XElement e, boolean reuse)
          Add an element to the XML tree according to a path.
 XElement addElement(XElement e)
          Add an element as a child of this node.
 String getAttribute(String attname)
          Retrieve one of this element's attributes
 XElement getElement(String localname)
          Lookup an element in this node's children.
 int getIndex()
           
 String getLocalName()
           
 String getName()
           
 String getNamespace()
           
 int getNodeCount()
           
 XVector getNodes()
           
 String getValue()
           
 boolean isLeaf()
           
static void main(String[] args)
          Test program
 String normalize(String path)
           
 void setValue(String value)
           
 void toggleHeader(boolean h)
           
 XHashtable toHashtable()
           
 XHashtable toHashtable(boolean local)
           
 String toString()
           
protected  String toString(int indent)
          Utilitary function (like toString(), but indented)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XElement

public XElement()

XElement

public XElement(String name)

XElement

public XElement(String name,
                String value)
Method Detail

toggleHeader

public void toggleHeader(boolean h)

getName

public String getName()

getLocalName

public String getLocalName()

getNamespace

public String getNamespace()

setValue

public void setValue(String value)

getValue

public String getValue()

isLeaf

public boolean isLeaf()

getIndex

public int getIndex()

addAttribute

public void addAttribute(String attname,
                         String attval)
Add an attribute to this XML element


getAttribute

public String getAttribute(String attname)
Retrieve one of this element's attributes


addElement

public XElement addElement(XElement e)
Add an element as a child of this node. If there are already children with the same name, the new element is added with a higher index (for example, adding a "book" to a "library" that already contains 10 books will create and add "book[11]").


getElement

public XElement getElement(String localname)
Lookup an element in this node's children.

Parameters:
localname - the element name to lookup (possibly postfixed with an index). If no index is provided, the 1st child with this element name is returned (equivalent to localname[1]).

getNodeCount

public int getNodeCount()

getNodes

public XVector getNodes()

addElement

public boolean addElement(String path,
                          XElement e,
                          boolean reuse)
Add an element to the XML tree according to a path. If some nodes in the path are not present, they will be created.

Parameters:
path - A path in the XML tree (with an XPath-like syntax).
Path syntax: /element{/element}* Element syntax: name{[position]} Examples:
  • /library/book/author
  • /library/book[2]/author
e - The element to add in the XML tree
reuse - Reuse existing elements or duplicate them. If reuse is true, two calls to addElement() with path=/library/book and an "author" element will produce:
 /library[1]/book[1]/author[1]
 /library[1]/book[1]/author[2]
 (1 library containing 1 book with 2 authors).
 
If reuse is false, the same call will produce:
 /library[1]/book[1]/author[1]
 /library[2]/book[1]/author[1]
 (2 libraries, each one containing 1 book with 1 author).
 
Note that reuse=false can be combined with indexes in the path; the same example with path=/library[1]/book would produce:
 /library[1]/book[1]/author[1]
 /library[1]/book[2]/author[1]
 (2 books, each one with 1 author, in the same library).
 

addElement

public boolean addElement(String elname,
                          String val)
Add an element to the XML tree according to a "path/name" string. If some nodes in the path are not present, they will be created. Existing nodes in the path will be reused.

Parameters:
elname - The element name, composed of a path in the XML tree (with an XPath-like syntax) + "/" + an element name.
val - The element value to add in the XML tree (in String format)

normalize

public String normalize(String path)

toString

public String toString()
Overrides:
toString in class Object

toString

protected String toString(int indent)
Utilitary function (like toString(), but indented)


toHashtable

public XHashtable toHashtable()

toHashtable

public XHashtable toHashtable(boolean local)

main

public static void main(String[] args)
Test program