de.pdark.decentxml
Class Element

java.lang.Object
  extended by de.pdark.decentxml.NodeWithChildren
      extended by de.pdark.decentxml.Element
All Implemented Interfaces:
Child, Node, Parent, TextNode

public class Element
extends NodeWithChildren
implements Child, TextNode

An element in a XML document.

Elements can have attributes and they have children like a document.

Author:
digulla
See Also:
Document, Attribute

Field Summary
static NodeFilter ELEMENT_FILTER
           
 
Constructor Summary
Element(Parent parent, java.lang.String name)
           
Element(Parent parent, java.lang.String name, Namespace ns)
           
Element(java.lang.String name)
           
Element(java.lang.String name, Namespace ns)
           
Element(Token token)
           
 
Method Summary
 Element addAttribute(Attribute a)
           
 Element addAttribute(java.lang.String name, java.lang.String value)
           
 Element addAttributes(Attribute... attributes)
           
 Element addNode(int index, Node node)
           
 Element addNode(Node node)
           
 Element addNodes(java.util.Collection<? extends Node> nodes)
           
 Element addNodes(int index, java.util.Collection<? extends Node> nodes)
           
 Element addNodes(int index, Node... nodes)
           
 Element addNodes(Node... nodes)
           
 Element checkMandatoryAttribute(java.lang.String name)
           
 int childIndexOf(Element element)
           
 Element clearChildNodes()
          Deprecated. Use Element.clearChildren() instead
 Element clearChildren()
           
 Element clearText()
           
 Element copy()
          Simulate clone()
 Element copy(Node orig)
          Copy all data from orig into this
 Element createClone()
          Simulate clone()
 Attribute getAttribute(java.lang.String name)
           
 Attribute getAttribute(java.lang.String name, Namespace ns)
           
 java.util.Map<java.lang.String,Attribute> getAttributeMap()
           
 java.util.List<Attribute> getAttributes()
           
 java.lang.String getAttributeValue(java.lang.String name)
           
 java.lang.String getAttributeValue(java.lang.String name, Namespace ns)
           
 java.lang.String getBeginName()
           
 Element getChild(int index)
           
 Element getChild(java.lang.String path)
          Find a child element (not a node!) by path
 Element getChild(java.lang.String path, Namespace ns)
           
 java.lang.String getChildPath()
           
 java.util.List<Element> getChildren()
           
 java.util.List<Element> getChildren(java.lang.String name)
           
 java.util.List<Element> getChildren(java.lang.String name, Namespace ns)
           
 Document getDocument()
           
 java.lang.String getEndName()
           
 int getEndOffset()
           
 java.lang.String getName()
           
 Namespace getNamespace()
           
 java.lang.String getNodePath()
          Deprecated. Use Element.getChildPath() instead
 java.lang.String getNormalizedText()
           
 Parent getParent()
          The parent of this child
 Element getParentElement()
           
 java.lang.String getPostSpace()
          Space before the closing bracket of the element
 int getStartOffset()
           
 Token getStartToken()
           
 java.lang.String getText()
          Get the text from the node
 java.lang.String getTrimmedText()
           
 XMLTokenizer.Type getType()
          Get the node type
 boolean hasChildren()
           
 boolean isCompactEmpty()
           
 Element removeAttribute(java.lang.String name)
           
 Element setAttribute(Attribute a)
           
 Element setAttribute(java.lang.String name, java.lang.String value)
           
 Element setAttribute(java.lang.String name, java.lang.String value, Namespace ns)
           
 Element setBeginName(java.lang.String beginName)
           
 Element setCompactEmpty(boolean compactEmpty)
           
 Element setEndName(java.lang.String endName)
          The string to be put into the end tag.
 Element setName(java.lang.String name)
           
 void setNamespace(Namespace namespace)
           
 Element setParent(Parent parent)
          Change the parent of this child.
 Element setPostSpace(java.lang.String postSpace)
           
 Element setText(java.lang.String text)
          Change the text of the node.
 Element toXML(XMLWriter writer)
          Fast way to convert many nodes to XML
 
Methods inherited from class de.pdark.decentxml.NodeWithChildren
clearNodes, getNode, getNodes, getNodes, hasNodes, nodeCount, nodeIndexOf, removeNode, removeNode, toString, toXML
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.pdark.decentxml.Node
toXML
 

Field Detail

ELEMENT_FILTER

public static final NodeFilter ELEMENT_FILTER
Constructor Detail

Element

public Element(Token token)

Element

public Element(java.lang.String name)

Element

public Element(Parent parent,
               java.lang.String name)

Element

public Element(java.lang.String name,
               Namespace ns)

Element

public Element(Parent parent,
               java.lang.String name,
               Namespace ns)
Method Detail

getStartToken

public Token getStartToken()

getStartOffset

public int getStartOffset()

getEndOffset

public int getEndOffset()

getBeginName

public java.lang.String getBeginName()

setBeginName

public Element setBeginName(java.lang.String beginName)

getEndName

public java.lang.String getEndName()

setEndName

public Element setEndName(java.lang.String endName)
The string to be put into the end tag. This can contain whitespace around the name


getPostSpace

public java.lang.String getPostSpace()
Space before the closing bracket of the element


setPostSpace

public Element setPostSpace(java.lang.String postSpace)

setName

public Element setName(java.lang.String name)

getName

public java.lang.String getName()

getParent

public Parent getParent()
Description copied from interface: Child
The parent of this child

Specified by:
getParent in interface Child

setParent

public Element setParent(Parent parent)
Description copied from interface: Child
Change the parent of this child.

CAUTION: If the child is already attached to a parent, this call will not detach the old relation! You must call child.getParent().removeNode (child), first!

Specified by:
setParent in interface Child

addAttributes

public Element addAttributes(Attribute... attributes)

addAttribute

public Element addAttribute(java.lang.String name,
                            java.lang.String value)

addAttribute

public Element addAttribute(Attribute a)

setAttribute

public Element setAttribute(Attribute a)

getAttributes

public java.util.List<Attribute> getAttributes()

getAttributeMap

public java.util.Map<java.lang.String,Attribute> getAttributeMap()

getAttribute

public Attribute getAttribute(java.lang.String name,
                              Namespace ns)

getAttribute

public Attribute getAttribute(java.lang.String name)

setAttribute

public Element setAttribute(java.lang.String name,
                            java.lang.String value)

setAttribute

public Element setAttribute(java.lang.String name,
                            java.lang.String value,
                            Namespace ns)

checkMandatoryAttribute

public Element checkMandatoryAttribute(java.lang.String name)

removeAttribute

public Element removeAttribute(java.lang.String name)

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String name)

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String name,
                                          Namespace ns)

addNode

public Element addNode(Node node)
Specified by:
addNode in interface Parent
Overrides:
addNode in class NodeWithChildren

addNode

public Element addNode(int index,
                       Node node)
Specified by:
addNode in interface Parent
Overrides:
addNode in class NodeWithChildren

addNodes

public Element addNodes(java.util.Collection<? extends Node> nodes)
Specified by:
addNodes in interface Parent
Overrides:
addNodes in class NodeWithChildren

addNodes

public Element addNodes(int index,
                        java.util.Collection<? extends Node> nodes)
Specified by:
addNodes in interface Parent
Overrides:
addNodes in class NodeWithChildren

addNodes

public Element addNodes(Node... nodes)
Specified by:
addNodes in interface Parent
Overrides:
addNodes in class NodeWithChildren

addNodes

public Element addNodes(int index,
                        Node... nodes)
Specified by:
addNodes in interface Parent
Overrides:
addNodes in class NodeWithChildren

setCompactEmpty

public Element setCompactEmpty(boolean compactEmpty)

isCompactEmpty

public boolean isCompactEmpty()

toXML

public Element toXML(XMLWriter writer)
              throws java.io.IOException
Description copied from interface: Node
Fast way to convert many nodes to XML

Specified by:
toXML in interface Node
Overrides:
toXML in class NodeWithChildren
Throws:
java.io.IOException

getType

public XMLTokenizer.Type getType()
Description copied from interface: Node
Get the node type

Specified by:
getType in interface Node

getChild

public Element getChild(int index)

hasChildren

public boolean hasChildren()

getChildren

public java.util.List<Element> getChildren()

getChildren

public java.util.List<Element> getChildren(java.lang.String name)

getChildren

public java.util.List<Element> getChildren(java.lang.String name,
                                           Namespace ns)

clearChildNodes

public Element clearChildNodes()
Deprecated. Use Element.clearChildren() instead


clearChildren

public Element clearChildren()

getText

public java.lang.String getText()
Description copied from interface: TextNode
Get the text from the node

Specified by:
getText in interface TextNode

getTrimmedText

public java.lang.String getTrimmedText()

getNormalizedText

public java.lang.String getNormalizedText()

setText

public Element setText(java.lang.String text)
Description copied from interface: TextNode
Change the text of the node. When necessary, the text will be escaped before writing it to the output stream.

Specified by:
setText in interface TextNode

clearText

public Element clearText()

getParentElement

public Element getParentElement()

getNodePath

public java.lang.String getNodePath()
Deprecated. Use Element.getChildPath() instead

Description copied from interface: Child
Return a path which uniquely describes this child.

Specified by:
getNodePath in interface Child

getChildPath

public java.lang.String getChildPath()

childIndexOf

public int childIndexOf(Element element)

getDocument

public Document getDocument()

getChild

public Element getChild(java.lang.String path)
Description copied from interface: Parent
Find a child element (not a node!) by path

Specified by:
getChild in interface Parent

getChild

public Element getChild(java.lang.String path,
                        Namespace ns)

createClone

public Element createClone()
Description copied from interface: Node
Simulate clone()

Specified by:
createClone in interface Node

copy

public Element copy(Node orig)
Description copied from interface: Node
Copy all data from orig into this

Specified by:
copy in interface Node
Overrides:
copy in class NodeWithChildren

copy

public Element copy()
Description copied from interface: Node
Simulate clone()

Specified by:
copy in interface Node
Overrides:
copy in class NodeWithChildren

setNamespace

public void setNamespace(Namespace namespace)

getNamespace

public Namespace getNamespace()


Copyright © 2008-2011. All Rights Reserved.