org.xmlpull.v1.builder
Interface XmlElement

All Superinterfaces:
java.lang.Cloneable, XmlContained, XmlContainer
All Known Implementing Classes:
XmlElementAdapter, XmlElementImpl

public interface XmlElement
extends XmlContainer, XmlContained, java.lang.Cloneable

Represents Element Information Item except for in-scope namespaces that can be reconstructed by visiting this element parent, checking its namespaces, then grandparent and so on. For convenience there are methods to resolve namespace prefix for given namespace name.
NOTE: this representaiton is optimized for streaming - iterator approach that allows gradual visiting of nodes is preferred over indexed access.


Field Summary
static java.lang.String NO_NAMESPACE
           
 
Method Summary
 XmlAttribute addAttribute(java.lang.String name, java.lang.String value)
          addAttribute
 XmlAttribute addAttribute(java.lang.String attributeType, java.lang.String attributePrefix, java.lang.String attributeNamespace, java.lang.String attributeName, java.lang.String attributeValue, boolean specified)
          Method addAttribute
 XmlAttribute addAttribute(java.lang.String type, XmlNamespace namespace, java.lang.String name, java.lang.String value)
          Method addAttribute
 XmlAttribute addAttribute(java.lang.String type, XmlNamespace namespace, java.lang.String name, java.lang.String value, boolean specified)
          Method addAttribute
 XmlAttribute addAttribute(XmlAttribute attributeValueToAdd)
          Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mist
 XmlAttribute addAttribute(XmlNamespace namespace, java.lang.String name, java.lang.String value)
          Method addAttribute
 void addChild(int pos, java.lang.Object child)
          Method addChild
 void addChild(java.lang.Object child)
          NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!
 XmlElement addElement(int pos, XmlElement child)
          Method addElement
 XmlElement addElement(java.lang.String name)
          Method addElement
 XmlElement addElement(XmlElement el)
          NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() !
 XmlElement addElement(XmlNamespace namespace, java.lang.String name)
          Method addElement
 XmlAttribute attribute(java.lang.String attributeName)
          Find attribute that matches given name or namespace Returns null if not found.
 XmlAttribute attribute(XmlNamespace attributeNamespaceName, java.lang.String attributeName)
          Find attribute that matches given name or namespace Returns null if not found.
 java.util.Iterator attributes()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 java.util.Iterator children()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 java.lang.Object clone()
          Method clone
 XmlNamespace declareNamespace(java.lang.String prefix, java.lang.String namespaceName)
          Create new namespace with prefix and namespace name (both must be not null) and add it to current element.
 XmlNamespace declareNamespace(XmlNamespace namespace)
          Add namespace to current element (both prefix and namespace name must be not null)
 XmlElement element(int position)
          return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect
 XmlElement element(XmlNamespace n, java.lang.String name)
          find first element with name and namespace (if namespace is null it is ignored in search)
 XmlElement element(XmlNamespace n, java.lang.String name, boolean create)
          find first element with name and namespace (if namespace is null it is ignored in search) if no matching element is found then new element is created, appended to children, and returned
 Iterable elements(XmlNamespace n, java.lang.String name)
          Return all elements that has namespace and name (null is never returned but empty iteraotr)
 void ensureAttributeCapacity(int minCapacity)
          Method ensureAttributeCapacity
 void ensureChildrenCapacity(int minCapacity)
          Method ensureChildrenCapacity
 void ensureNamespaceDeclarationsCapacity(int minCapacity)
          Method ensureNamespaceDeclarationsCapacity
 XmlAttribute findAttribute(java.lang.String attributeNamespaceName, java.lang.String attributeName)
          Deprecated. Use attribute()
 XmlElement findElementByName(java.lang.String name)
          Deprecated. see element()
 XmlElement findElementByName(java.lang.String namespaceName, java.lang.String name)
          Deprecated. see element()
 XmlElement findElementByName(java.lang.String namespaceName, java.lang.String name, XmlElement elementToStartLooking)
          Deprecated. see elements()
 XmlElement findElementByName(java.lang.String name, XmlElement elementToStartLooking)
          Deprecated. see elements()
 java.lang.String getAttributeValue(java.lang.String attributeNamespaceName, java.lang.String attributeName)
          Method getAttributeValue
 java.lang.String getBaseUri()
          XML Infoset [base URI] property
 java.lang.String getName()
          XML Infoset [local name] property.
 XmlNamespace getNamespace()
          Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespace
 java.lang.String getNamespaceName()
          Return namespace name (XML Infoset [namespace name]property or null if element has no namespace
 XmlContainer getParent()
          XML Infoset [parent] property.
 XmlContainer getRoot()
          Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)
 boolean hasAttributes()
          Method hasAttributes
 boolean hasChild(java.lang.Object child)
          Method hasChild
 boolean hasChildren()
          Method hasChildren
 boolean hasNamespaceDeclarations()
          Method hasNamespaceDeclarations
 void insertChild(int pos, java.lang.Object childToInsert)
           
 XmlNamespace lookupNamespaceByName(java.lang.String namespaceName)
          Find namespace (will have non empty prefix) corresponding to namespace name checking first current elemen and if not found continue in parent (if element has parent).
 XmlNamespace lookupNamespaceByPrefix(java.lang.String namespacePrefix)
          Find namespace (will have non empty prefix) corresponding to namespace prefix checking first current elemen and if not found continue in parent (if element has parent) and so on.
 java.util.Iterator namespaces()
          Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned
 XmlElement newElement(java.lang.String name)
          Create unattached element
 XmlElement newElement(java.lang.String namespaceName, java.lang.String name)
          Method newElement
 XmlElement newElement(XmlNamespace namespace, java.lang.String name)
          Method newElement
 XmlNamespace newNamespace(java.lang.String namespaceName)
          Create new namespace with null prefix (namespace name must be not null).
 XmlNamespace newNamespace(java.lang.String prefix, java.lang.String namespaceName)
          Create new namespace with prefix and namespace name (both must be not null).
 void removeAllAttributes()
          Method removeAllAttributes
 void removeAllChildren()
          Removes all children - every child that was implementing XmlNode will have set parent to null.
 void removeAllNamespaceDeclarations()
          Method removeAllNamespaceDeclarations
 void removeAttribute(XmlAttribute attr)
          Method removeAttribute
 void removeChild(java.lang.Object child)
          Method removeChild
 void replaceChild(java.lang.Object newChild, java.lang.Object oldChild)
          Method replaceChild
 void replaceChildrenWithText(java.lang.String textContent)
          Remove all children and then add this text as only child.
 XmlElement requiredElement(XmlNamespace n, java.lang.String name)
          call element(n, name) and if null was returnedthrow XmlBuilderException
 Iterable requiredElementContent()
          Return Iterator - that represents all XmlElement content.
 java.lang.String requiredTextContent()
          return children content as text - if there are any no text children throw exception
 void setBaseUri(java.lang.String baseUri)
          XML Infoset [base URI] property
 void setName(java.lang.String name)
          XML Infoset [local name] property.
 void setNamespace(XmlNamespace namespace)
          Set namespace ot use for theis element.
 void setParent(XmlContainer parent)
          Method setParent
 

Field Detail

NO_NAMESPACE

static final java.lang.String NO_NAMESPACE
See Also:
Constant Field Values
Method Detail

clone

java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Method clone

Returns:
an Object
Throws:
java.lang.CloneNotSupportedException

getBaseUri

java.lang.String getBaseUri()
XML Infoset [base URI] property

Returns:
a String

setBaseUri

void setBaseUri(java.lang.String baseUri)
XML Infoset [base URI] property

Parameters:
baseUri - a String

getRoot

XmlContainer getRoot()
Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)


getParent

XmlContainer getParent()
XML Infoset [parent] property. If current element is not child of containing parent XmlElement or XmlDocument then builder exception will be thrown

Specified by:
getParent in interface XmlContained

setParent

void setParent(XmlContainer parent)
Method setParent

Specified by:
setParent in interface XmlContained
Parameters:
parent - a XmlContainer

getNamespace

XmlNamespace getNamespace()
Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespace


getNamespaceName

java.lang.String getNamespaceName()
Return namespace name (XML Infoset [namespace name]property or null if element has no namespace


setNamespace

void setNamespace(XmlNamespace namespace)
Set namespace ot use for theis element. Note: namespace prefix is always ignored.


getName

java.lang.String getName()
XML Infoset [local name] property.

Returns:
a String

setName

void setName(java.lang.String name)
XML Infoset [local name] property.

Parameters:
name - a String

attributes

java.util.Iterator attributes()
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned


addAttribute

XmlAttribute addAttribute(XmlAttribute attributeValueToAdd)
Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mist

Parameters:
attributeValueToAdd - a XmlAttribute
Returns:
a XmlAttribute

addAttribute

XmlAttribute addAttribute(java.lang.String name,
                          java.lang.String value)
addAttribute

Parameters:
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

XmlAttribute addAttribute(XmlNamespace namespace,
                          java.lang.String name,
                          java.lang.String value)
Method addAttribute

Parameters:
namespace - a XmlNamespace
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

XmlAttribute addAttribute(java.lang.String type,
                          XmlNamespace namespace,
                          java.lang.String name,
                          java.lang.String value)
Method addAttribute

Parameters:
type - a String
namespace - a XmlNamespace
name - a String
value - a String
Returns:
a XmlAttribute

addAttribute

XmlAttribute addAttribute(java.lang.String type,
                          XmlNamespace namespace,
                          java.lang.String name,
                          java.lang.String value,
                          boolean specified)
Method addAttribute

Parameters:
type - a String
namespace - a XmlNamespace
name - a String
value - a String
specified - a boolean
Returns:
a XmlAttribute

addAttribute

XmlAttribute addAttribute(java.lang.String attributeType,
                          java.lang.String attributePrefix,
                          java.lang.String attributeNamespace,
                          java.lang.String attributeName,
                          java.lang.String attributeValue,
                          boolean specified)
Method addAttribute

Parameters:
attributeType - a String
attributePrefix - a String
attributeNamespace - a String
attributeName - a String
attributeValue - a String
specified - a boolean
Returns:
a XmlAttribute

ensureAttributeCapacity

void ensureAttributeCapacity(int minCapacity)
Method ensureAttributeCapacity

Parameters:
minCapacity - an int

getAttributeValue

java.lang.String getAttributeValue(java.lang.String attributeNamespaceName,
                                   java.lang.String attributeName)
Method getAttributeValue

Parameters:
attributeNamespaceNamea - String
attributeName - a String
Returns:
a String

attribute

XmlAttribute attribute(java.lang.String attributeName)
Find attribute that matches given name or namespace Returns null if not found. Will match only attribute that have no namesapce.


attribute

XmlAttribute attribute(XmlNamespace attributeNamespaceName,
                       java.lang.String attributeName)
Find attribute that matches given name or namespace Returns null if not found. NOTE: if namespace is null in this case it will match only attributes that have no namespace.


findAttribute

XmlAttribute findAttribute(java.lang.String attributeNamespaceName,
                           java.lang.String attributeName)
Deprecated. Use attribute()

Find attribute that matches given name or namespace Returns null if not found. NOTE: if namespace is null in this case it will match only attributes that has no namespace.


hasAttributes

boolean hasAttributes()
Method hasAttributes

Returns:
a boolean

removeAttribute

void removeAttribute(XmlAttribute attr)
Method removeAttribute

Parameters:
attr - a XmlAttribute

removeAllAttributes

void removeAllAttributes()
Method removeAllAttributes


namespaces

java.util.Iterator namespaces()
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned


declareNamespace

XmlNamespace declareNamespace(java.lang.String prefix,
                              java.lang.String namespaceName)
Create new namespace with prefix and namespace name (both must be not null) and add it to current element.


declareNamespace

XmlNamespace declareNamespace(XmlNamespace namespace)
Add namespace to current element (both prefix and namespace name must be not null)


ensureNamespaceDeclarationsCapacity

void ensureNamespaceDeclarationsCapacity(int minCapacity)
Method ensureNamespaceDeclarationsCapacity

Parameters:
minCapacity - an int

hasNamespaceDeclarations

boolean hasNamespaceDeclarations()
Method hasNamespaceDeclarations

Returns:
a boolean

lookupNamespaceByPrefix

XmlNamespace lookupNamespaceByPrefix(java.lang.String namespacePrefix)
Find namespace (will have non empty prefix) corresponding to namespace prefix checking first current elemen and if not found continue in parent (if element has parent) and so on.


lookupNamespaceByName

XmlNamespace lookupNamespaceByName(java.lang.String namespaceName)
Find namespace (will have non empty prefix) corresponding to namespace name checking first current elemen and if not found continue in parent (if element has parent). and so on.


newNamespace

XmlNamespace newNamespace(java.lang.String namespaceName)
Create new namespace with null prefix (namespace name must be not null).


newNamespace

XmlNamespace newNamespace(java.lang.String prefix,
                          java.lang.String namespaceName)
Create new namespace with prefix and namespace name (both must be not null).


removeAllNamespaceDeclarations

void removeAllNamespaceDeclarations()
Method removeAllNamespaceDeclarations


children

java.util.Iterator children()
Return Iterator - null is never returned if there is no children then iteraotr over empty collection is returned


addChild

void addChild(java.lang.Object child)
NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!


addChild

void addChild(int pos,
              java.lang.Object child)
Method addChild

Parameters:
pos - an int (starting from 0)
child - an Object

addElement

XmlElement addElement(XmlElement el)
NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() != null)


addElement

XmlElement addElement(int pos,
                      XmlElement child)
Method addElement

Parameters:
pos - an int (starting from 0)
child - a XmlElement
Returns:
a XmlElement

addElement

XmlElement addElement(java.lang.String name)
Method addElement

Parameters:
name - a String
Returns:
a XmlElement

addElement

XmlElement addElement(XmlNamespace namespace,
                      java.lang.String name)
Method addElement

Parameters:
namespace - a XmlNamespace
name - a String
Returns:
a XmlElement

hasChildren

boolean hasChildren()
Method hasChildren

Returns:
a boolean

hasChild

boolean hasChild(java.lang.Object child)
Method hasChild

Parameters:
child - an Object
Returns:
a boolean

ensureChildrenCapacity

void ensureChildrenCapacity(int minCapacity)
Method ensureChildrenCapacity

Parameters:
minCapacity - an int

findElementByName

XmlElement findElementByName(java.lang.String name)
Deprecated. see element()


findElementByName

XmlElement findElementByName(java.lang.String namespaceName,
                             java.lang.String name)
Deprecated. see element()


findElementByName

XmlElement findElementByName(java.lang.String name,
                             XmlElement elementToStartLooking)
Deprecated. see elements()


findElementByName

XmlElement findElementByName(java.lang.String namespaceName,
                             java.lang.String name,
                             XmlElement elementToStartLooking)
Deprecated. see elements()


element

XmlElement element(int position)
return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrect


requiredElement

XmlElement requiredElement(XmlNamespace n,
                           java.lang.String name)
                           throws XmlBuilderException
call element(n, name) and if null was returnedthrow XmlBuilderException

Throws:
XmlBuilderException

element

XmlElement element(XmlNamespace n,
                   java.lang.String name)
find first element with name and namespace (if namespace is null it is ignored in search)


element

XmlElement element(XmlNamespace n,
                   java.lang.String name,
                   boolean create)
find first element with name and namespace (if namespace is null it is ignored in search) if no matching element is found then new element is created, appended to children, and returned


elements

Iterable elements(XmlNamespace n,
                  java.lang.String name)
Return all elements that has namespace and name (null is never returned but empty iteraotr)


insertChild

void insertChild(int pos,
                 java.lang.Object childToInsert)

newElement

XmlElement newElement(java.lang.String name)
Create unattached element


newElement

XmlElement newElement(XmlNamespace namespace,
                      java.lang.String name)
Method newElement

Parameters:
namespace - a XmlNamespace
name - a String
Returns:
a XmlElement

newElement

XmlElement newElement(java.lang.String namespaceName,
                      java.lang.String name)
Method newElement

Parameters:
namespaceName - a String
name - a String
Returns:
a XmlElement

removeAllChildren

void removeAllChildren()
Removes all children - every child that was implementing XmlNode will have set parent to null.


removeChild

void removeChild(java.lang.Object child)
Method removeChild

Parameters:
child - an Object

replaceChild

void replaceChild(java.lang.Object newChild,
                  java.lang.Object oldChild)
Method replaceChild

Parameters:
newChild - an Object
oldChild - an Object

requiredElementContent

Iterable requiredElementContent()
Return Iterator - that represents all XmlElement content. When used exception will be thrown if non white space children are found (as expected no mixed content!).


requiredTextContent

java.lang.String requiredTextContent()
return children content as text - if there are any no text children throw exception


replaceChildrenWithText

void replaceChildrenWithText(java.lang.String textContent)
Remove all children and then add this text as only child.