Package org.xmlpull.v1.builder
Interface XmlElement
-
- All Superinterfaces:
Cloneable,XmlContained,XmlContainer
- All Known Implementing Classes:
XmlElementAdapter,XmlElementImpl
public interface XmlElement extends XmlContainer, XmlContained, 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.- Version:
- $Revision: 1.25 $
- Author:
- Aleksander Slominski
-
-
Field Summary
Fields Modifier and Type Field Description static StringNO_NAMESPACE
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description XmlAttributeaddAttribute(String name, String value)addAttributeXmlAttributeaddAttribute(String attributeType, String attributePrefix, String attributeNamespace, String attributeName, String attributeValue, boolean specified)Method addAttributeXmlAttributeaddAttribute(String type, XmlNamespace namespace, String name, String value)Method addAttributeXmlAttributeaddAttribute(String type, XmlNamespace namespace, String name, String value, boolean specified)Method addAttributeXmlAttributeaddAttribute(XmlAttribute attributeValueToAdd)Add attribute (adds it to the XML Infoset [namespace attributes] set) Attribute mistXmlAttributeaddAttribute(XmlNamespace namespace, String name, String value)Method addAttributevoidaddChild(int pos, Object child)Method addChildvoidaddChild(Object child)NOTE: =child added is _not_ checked if it XmlContainer, caller must manually fix parent in child by calling setParent() !!!!XmlElementaddElement(int pos, XmlElement child)Method addElementXmlElementaddElement(String name)Method addElementXmlElementaddElement(XmlElement el)NOTE: the child element must unattached to be added (it is atttached if it is XmlContainer of recognized type and getParent() != null)XmlElementaddElement(XmlNamespace namespace, String name)Method addElementXmlAttributeattribute(String attributeName)Find attribute that matches given name or namespace Returns null if not found.XmlAttributeattribute(XmlNamespace attributeNamespaceName, String attributeName)Find attribute that matches given name or namespace Returns null if not found.Iteratorattributes()Return Iterator- null is never returned if there is no children then iteraotr over empty collection is returned Iteratorchildren()Return IteratorObjectclone()Method cloneXmlNamespacedeclareNamespace(String prefix, String namespaceName)Create new namespace with prefix and namespace name (both must be not null) and add it to current element.XmlNamespacedeclareNamespace(XmlNamespace namespace)Add namespace to current element (both prefix and namespace name must be not null)XmlElementelement(int position)return element at poition (0..count-1) or IndexOutOfBoundsException if positon incorrectXmlElementelement(XmlNamespace n, String name)find first element with name and namespace (if namespace is null it is ignored in search)XmlElementelement(XmlNamespace n, 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 returnedIterableelements(XmlNamespace n, String name)Return all elements that has namespace and name (null is never returned but empty iteraotr)voidensureAttributeCapacity(int minCapacity)Method ensureAttributeCapacityvoidensureChildrenCapacity(int minCapacity)Method ensureChildrenCapacityvoidensureNamespaceDeclarationsCapacity(int minCapacity)Method ensureNamespaceDeclarationsCapacityXmlAttributefindAttribute(String attributeNamespaceName, String attributeName)Deprecated.Use attribute()XmlElementfindElementByName(String name)Deprecated.see element()XmlElementfindElementByName(String namespaceName, String name)Deprecated.see element()XmlElementfindElementByName(String namespaceName, String name, XmlElement elementToStartLooking)Deprecated.see elements()XmlElementfindElementByName(String name, XmlElement elementToStartLooking)Deprecated.see elements()StringgetAttributeValue(String attributeNamespaceName, String attributeName)Method getAttributeValueStringgetBaseUri()XML Infoset [base URI] propertyStringgetName()XML Infoset [local name] property.XmlNamespacegetNamespace()Return namespace of current element (XML Infoset [namespace name] and [prefix] properties combined) null is only returned if element was created without namespaceStringgetNamespaceName()Return namespace name (XML Infoset [namespace name]property or null if element has no namespaceXmlContainergetParent()XML Infoset [parent] property.XmlContainergetRoot()Get top most container that is either XmlDocument or XmlElement (may be event this element!!!)booleanhasAttributes()Method hasAttributesbooleanhasChild(Object child)Method hasChildbooleanhasChildren()Method hasChildrenbooleanhasNamespaceDeclarations()Method hasNamespaceDeclarationsvoidinsertChild(int pos, Object childToInsert)XmlNamespacelookupNamespaceByName(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).XmlNamespacelookupNamespaceByPrefix(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.Iteratornamespaces()Return Iterator- null is never returned if there is no children then iteraotr over empty collection is returned XmlElementnewElement(String name)Create unattached elementXmlElementnewElement(String namespaceName, String name)Method newElementXmlElementnewElement(XmlNamespace namespace, String name)Method newElementXmlNamespacenewNamespace(String namespaceName)Create new namespace with null prefix (namespace name must be not null).XmlNamespacenewNamespace(String prefix, String namespaceName)Create new namespace with prefix and namespace name (both must be not null).voidremoveAllAttributes()Method removeAllAttributesvoidremoveAllChildren()Removes all children - every child that was implementing XmlNode will have set parent to null.voidremoveAllNamespaceDeclarations()Method removeAllNamespaceDeclarationsvoidremoveAttribute(XmlAttribute attr)Method removeAttributevoidremoveChild(Object child)Method removeChildvoidreplaceChild(Object newChild, Object oldChild)Method replaceChildvoidreplaceChildrenWithText(String textContent)Remove all children and then add this text as only child.XmlElementrequiredElement(XmlNamespace n, String name)call element(n, name) and if null was returnedthrow XmlBuilderExceptionIterablerequiredElementContent()Return Iterator- that represents all XmlElement content. StringrequiredTextContent()return children content as text - if there are any no text children throw exceptionvoidsetBaseUri(String baseUri)XML Infoset [base URI] propertyvoidsetName(String name)XML Infoset [local name] property.voidsetNamespace(XmlNamespace namespace)Set namespace ot use for theis element.voidsetParent(XmlContainer parent)Method setParent
-
-
-
Field Detail
-
NO_NAMESPACE
static final String NO_NAMESPACE
- See Also:
- Constant Field Values
-
-
Method Detail
-
clone
Object clone() throws CloneNotSupportedException
Method clone- Returns:
- an Object
- Throws:
CloneNotSupportedException
-
getBaseUri
String getBaseUri()
XML Infoset [base URI] property- Returns:
- a String
-
setBaseUri
void setBaseUri(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:
getParentin interfaceXmlContained
-
setParent
void setParent(XmlContainer parent)
Method setParent- Specified by:
setParentin interfaceXmlContained- 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
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
String getName()
XML Infoset [local name] property.- Returns:
- a String
-
setName
void setName(String name)
XML Infoset [local name] property.- Parameters:
name- a String
-
attributes
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(String name, String value)
addAttribute- Parameters:
name- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
XmlAttribute addAttribute(XmlNamespace namespace, String name, String value)
Method addAttribute- Parameters:
namespace- a XmlNamespacename- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
XmlAttribute addAttribute(String type, XmlNamespace namespace, String name, String value)
Method addAttribute- Parameters:
type- a Stringnamespace- a XmlNamespacename- a Stringvalue- a String- Returns:
- a XmlAttribute
-
addAttribute
XmlAttribute addAttribute(String type, XmlNamespace namespace, String name, String value, boolean specified)
Method addAttribute- Parameters:
type- a Stringnamespace- a XmlNamespacename- a Stringvalue- a Stringspecified- a boolean- Returns:
- a XmlAttribute
-
addAttribute
XmlAttribute addAttribute(String attributeType, String attributePrefix, String attributeNamespace, String attributeName, String attributeValue, boolean specified)
Method addAttribute- Parameters:
attributeType- a StringattributePrefix- a StringattributeNamespace- a StringattributeName- a StringattributeValue- a Stringspecified- a boolean- Returns:
- a XmlAttribute
-
ensureAttributeCapacity
void ensureAttributeCapacity(int minCapacity)
Method ensureAttributeCapacity- Parameters:
minCapacity- an int
-
getAttributeValue
String getAttributeValue(String attributeNamespaceName, String attributeName)
Method getAttributeValue- Parameters:
attributeNamespaceNamea- StringattributeName- a String- Returns:
- a String
-
attribute
XmlAttribute attribute(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, 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(String attributeNamespaceName, 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
Iterator namespaces()
Return Iterator- null is never returned if there is no children then iteraotr over empty collection is returned
-
declareNamespace
XmlNamespace declareNamespace(String prefix, 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(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(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(String namespaceName)
Create new namespace with null prefix (namespace name must be not null).
-
newNamespace
XmlNamespace newNamespace(String prefix, String namespaceName)
Create new namespace with prefix and namespace name (both must be not null).
-
removeAllNamespaceDeclarations
void removeAllNamespaceDeclarations()
Method removeAllNamespaceDeclarations
-
children
Iterator children()
Return Iterator
-
addChild
void addChild(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, 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(String name)
Method addElement- Parameters:
name- a String- Returns:
- a XmlElement
-
addElement
XmlElement addElement(XmlNamespace namespace, String name)
Method addElement- Parameters:
namespace- a XmlNamespacename- a String- Returns:
- a XmlElement
-
hasChildren
boolean hasChildren()
Method hasChildren- Returns:
- a boolean
-
hasChild
boolean hasChild(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(String name)
Deprecated.see element()
-
findElementByName
XmlElement findElementByName(String namespaceName, String name)
Deprecated.see element()
-
findElementByName
XmlElement findElementByName(String name, XmlElement elementToStartLooking)
Deprecated.see elements()
-
findElementByName
XmlElement findElementByName(String namespaceName, 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, String name) throws XmlBuilderException
call element(n, name) and if null was returnedthrow XmlBuilderException- Throws:
XmlBuilderException
-
element
XmlElement element(XmlNamespace n, String name)
find first element with name and namespace (if namespace is null it is ignored in search)
-
element
XmlElement element(XmlNamespace n, 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, String name)
Return all elements that has namespace and name (null is never returned but empty iteraotr)
-
insertChild
void insertChild(int pos, Object childToInsert)
-
newElement
XmlElement newElement(String name)
Create unattached element
-
newElement
XmlElement newElement(XmlNamespace namespace, String name)
Method newElement- Parameters:
namespace- a XmlNamespacename- a String- Returns:
- a XmlElement
-
newElement
XmlElement newElement(String namespaceName, String name)
Method newElement- Parameters:
namespaceName- a Stringname- 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(Object child)
Method removeChild- Parameters:
child- an Object
-
replaceChild
void replaceChild(Object newChild, Object oldChild)
Method replaceChild- Parameters:
newChild- an ObjectoldChild- 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
String requiredTextContent()
return children content as text - if there are any no text children throw exception
-
replaceChildrenWithText
void replaceChildrenWithText(String textContent)
Remove all children and then add this text as only child.
-
-