uxparser
Class XElem

java.lang.Object
  extended by uxparser.XContent
      extended by uxparser.XElem

public class XElem
extends XContent

XElem models a XML Element construct.


Constructor Summary
XElem()
          Convenience for XElem(null, "unnamed").
XElem(java.lang.String name)
          Convenience for XElem(null, name).
XElem(java.lang.String nsPrefix, java.lang.String nsUri, java.lang.String name)
          Create a new element and define a new namespace attribute for the element using the specified prefix and uri.
XElem(XNs ns, java.lang.String name)
          Create a new element with the specified namespace and local name.
 
Method Summary
 XElem addAttr(java.lang.String name, java.lang.String value)
          Add the specified attribute name value pair using the null namespace.
 XElem addAttr(XNs ns, java.lang.String name, java.lang.String value)
          Add the specified attribute name value pair.
 XElem addContent(int index, XContent child)
          Insert the content instance as a child of this element at the specified index.
 XElem addContent(XContent child)
          Add the specified content to the end of the content list.
 XElem addText(java.lang.String txt)
          Creates and adds a text descendent.
 int attrIndex(java.lang.String name)
          Get the index of the first attribute with the specified name not in an explicit namespace.
 int attrIndex(XNs ns, java.lang.String name)
          Get the index of the first attribute with the specified namespace and local name or return -1 if no match.
 java.lang.String attrName(int index)
          Get the attribute name for the specified index.
 XNs attrNs(int index)
          Get the attribute namespace for the specified index.
 int attrSize()
          Get the number of attributes in this element.
 java.lang.String attrValue(int index)
          Get the attribute value for the specified index.
 void clearAttr()
          Clear the attribute list to a count of 0.
 void clearContent()
          Get the content children and set content count to 0.
 XContent[] content()
          Get the array of XContent children for this element.
 XContent content(int index)
          Get the XContent child at the specified index.
 int contentIndex(XContent child)
          Get the index of the specified content instance (using == operator) or return -1 if the specified content is not a child of this element.
 int contentSize()
          Get the number of XContent children of this element.
 XElem copy()
          Make a new cloned copy of this XElem instance.
 XNs defineDefaultNs(java.lang.String uri)
          Define the default namespace for this element and add the "xmlns" attribute.
 XNs defineNs(java.lang.String prefix, java.lang.String uri)
          Define the a new namespace for this element and add the "xmlns:" attribute.
 XNs defineNs(XNs ns)
          Define a namespace for this element by adding the "xmlns:" attribute.
 void dump()
          Dump to standard out.
 XElem elem(int index)
          Get the XContent at the specified index cast to a XElem.
 XElem elem(java.lang.String name)
          Get the first child element the specified local name regardless of namespace.
 XElem elem(XNs ns, java.lang.String name)
          Get the first child element in the specified namespace and with the specified local name.
 XElem[] elems()
          Get the array of XElem children for this element.
 XElem[] elems(java.lang.String name)
          Get all the children elements with the specified local name regardless of namespace.
 XElem[] elems(XNs ns)
          Get all the children elements in the specified namespace.
 XElem[] elems(XNs ns, java.lang.String name)
          Get all the children elements in the specified namespace and with the specified local name.
 XNs findNs(java.lang.String uri)
          Check is this element defines a namespace for the specified uri.
 java.lang.String get(java.lang.String name)
          Get an attribute by the specified name not in an explicit namespace.
 java.lang.String get(java.lang.String name, java.lang.String def)
          Get an attribute by the specified name.
 java.lang.String get(XNs ns, java.lang.String name)
          Get an attribute by the specified namespace and local name.
 java.lang.String get(XNs ns, java.lang.String name, java.lang.String def)
          Get an attribute by the specified namespace and local name.
 boolean getb(java.lang.String name)
          Get a boolean attribute by the specified name.
 boolean getb(java.lang.String name, boolean def)
          Get a boolean attribute by the specified name.
 double getd(java.lang.String name)
          Get a double attribute by the specified name.
 double getd(java.lang.String name, double def)
          Get a double attribute by the specified name.
 float getf(java.lang.String name)
          Get a float attribute by the specified name.
 float getf(java.lang.String name, float def)
          Get a float attribute by the specified name.
 int geti(java.lang.String name)
          Get an int attribute by the specified name.
 int geti(java.lang.String name, int def)
          Get an int attribute by the specified name.
 long getl(java.lang.String name)
          Get a long attribute by the specified name.
 long getl(java.lang.String name, long def)
          Get a long attribute by the specified name.
 int line()
          Get the line number of this element in the document or 0 if unknown.
 java.lang.String name()
          Get the local name of the element (without prefix).
 XNs ns()
          Get the namespace for this element.
 java.lang.String prefix()
          Return ns().prefix() or null if no namespace is defined for this element.
 java.lang.String qname()
          Get the qualified name of the element.
 void removeAttr(int index)
          Remove the attribute at the specified index.
 void removeAttr(java.lang.String name)
          Remove the first attribute with the specified name in the null namespace.
 void removeAttr(XNs ns, java.lang.String name)
          Remove the first attribute with the specified namespace and local name.
 void removeContent(int index)
          Remove the content child at the specified index.
 void removeContent(XContent child)
          Remove the specified content instance (using == operator).
 void replaceContent(int index, XContent child)
          Replace the content instance at the specified index with the new content child.
 void setAttr(int index, java.lang.String value)
          Set the attribute value at the specified index.
 void setAttr(java.lang.String name, java.lang.String value)
          Set the attribute value for the first attribute found with the specified name.
 void setAttr(XNs ns, java.lang.String name, java.lang.String value)
          Set the attribute value for the first attribute found with the specified namespace and local name.
 void setName(java.lang.String name)
          Set this element's local name.
 XNs setNs(XNs ns)
          Set this element's namespace.
 java.lang.String string()
          If the first content child is a XText instance, then return the result of calling XText.string().
 XText text()
          If the first content child is a XText instance, then return it.
 XText text(int index)
          Get the XContent at the specified index cast to a XText.
 java.lang.String toString()
          To string returns the start tag.
 java.lang.String uri()
          Return ns().uri() or null if no namespace is defined for this element.
 void write(java.io.File file)
          Write to the specified File.
 void write(XWriter out)
          Write to the specified XWriter stream with indent of 0.
 void write(XWriter out, int indent)
          Write to the specified XWriter stream.
 
Methods inherited from class uxparser.XContent
equals, parent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

XElem

public XElem(java.lang.String nsPrefix,
             java.lang.String nsUri,
             java.lang.String name)
Create a new element and define a new namespace attribute for the element using the specified prefix and uri.


XElem

public XElem(XNs ns,
             java.lang.String name)
Create a new element with the specified namespace and local name.


XElem

public XElem(java.lang.String name)
Convenience for XElem(null, name).


XElem

public XElem()
Convenience for XElem(null, "unnamed").

Method Detail

ns

public final XNs ns()
Get the namespace for this element. If no namespace has been defined for this element then return null.


prefix

public final java.lang.String prefix()
Return ns().prefix() or null if no namespace is defined for this element.


uri

public final java.lang.String uri()
Return ns().uri() or null if no namespace is defined for this element.


name

public final java.lang.String name()
Get the local name of the element (without prefix).


qname

public final java.lang.String qname()
Get the qualified name of the element. If this element has no namespace or is in the default namespace return the local name. Otherwise return ":".


findNs

public final XNs findNs(java.lang.String uri)
Check is this element defines a namespace for the specified uri. If we find one, then return an XNs instance for it, otherwise return null.


setNs

public final XNs setNs(XNs ns)
Set this element's namespace.


setName

public final void setName(java.lang.String name)
Set this element's local name.


defineDefaultNs

public XNs defineDefaultNs(java.lang.String uri)
Define the default namespace for this element and add the "xmlns" attribute. Return the XNs instance used to identify the namespace. Note this does not put this XElem in the namespace unless setNs() is called.


defineNs

public XNs defineNs(java.lang.String prefix,
                    java.lang.String uri)
Define the a new namespace for this element and add the "xmlns:" attribute. Return the XNs instance used to identify the namespace. Note this does not put this XElem in the namespace unless setNs() is called.


defineNs

public XNs defineNs(XNs ns)
Define a namespace for this element by adding the "xmlns:" attribute. Return the ns instance passed as the parameter. Note this does not put this XElem in the namespace unless setNs() is called.


attrSize

public final int attrSize()
Get the number of attributes in this element.


attrNs

public final XNs attrNs(int index)
Get the attribute namespace for the specified index. Return null if no namespace is defined for the attribute. Note that the special prefixes "xml" and "xmlns" return null for their namespace, and are combined into the name.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= attrSize()

attrName

public final java.lang.String attrName(int index)
Get the attribute name for the specified index. Note that the special prefixes "xml" and "xmlns" return null for their namespace, and are combined into the name.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= attrSize()

attrValue

public final java.lang.String attrValue(int index)
Get the attribute value for the specified index.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= attrSize()

attrIndex

public final int attrIndex(XNs ns,
                           java.lang.String name)
Get the index of the first attribute with the specified namespace and local name or return -1 if no match.


attrIndex

public final int attrIndex(java.lang.String name)
Get the index of the first attribute with the specified name not in an explicit namespace. Return -1 if no match.


get

public final java.lang.String get(XNs ns,
                                  java.lang.String name)
Get an attribute by the specified namespace and local name. If not found then throw XException. Note that the specific prefixes "xml" and "xmlns" are always combined into the name.


get

public final java.lang.String get(java.lang.String name)
Get an attribute by the specified name not in an explicit namespace. If not found then throw XException. Note that the specific prefixes "xml" and "xmlns" are always combined into the name.


get

public final java.lang.String get(XNs ns,
                                  java.lang.String name,
                                  java.lang.String def)
Get an attribute by the specified namespace and local name. If not found then return the given def value.


get

public final java.lang.String get(java.lang.String name,
                                  java.lang.String def)
Get an attribute by the specified name. If not found then return the given def value.


getb

public final boolean getb(java.lang.String name)
Get a boolean attribute by the specified name. If not found then return throw an XException. If the value cannot be parsed as "true" or "false" then throw an XException.


getb

public final boolean getb(java.lang.String name,
                          boolean def)
Get a boolean attribute by the specified name. If not found then return the given def value. If the value cannot be parsed as "true" or "false" then throw an XException.


geti

public final int geti(java.lang.String name)
Get an int attribute by the specified name. If not found then return throw an XException. If the value cannot be parsed then throw an XException.


geti

public final int geti(java.lang.String name,
                      int def)
Get an int attribute by the specified name. If not found then return the given def value. If the value cannot be parsed then throw an XException.


getl

public final long getl(java.lang.String name)
Get a long attribute by the specified name. If not found then return throw an XException. If the value cannot be parsed then throw an XException.


getl

public final long getl(java.lang.String name,
                       long def)
Get a long attribute by the specified name. If not found then return the given def value. If the value cannot be parsed then throw an XException.


getf

public final float getf(java.lang.String name)
Get a float attribute by the specified name. If not found then return throw an XException. If the value cannot be parsed then throw an XException.


getf

public final float getf(java.lang.String name,
                        float def)
Get a float attribute by the specified name. If not found then return the given def value. If the value cannot be parsed then throw an XException.


getd

public final double getd(java.lang.String name)
Get a double attribute by the specified name. If not found then return throw an XException. If the value cannot be parsed then throw an XException.


getd

public final double getd(java.lang.String name,
                         double def)
Get a double attribute by the specified name. If not found then return the given def value. If the value cannot be parsed then throw an XException.


setAttr

public final void setAttr(XNs ns,
                          java.lang.String name,
                          java.lang.String value)
Set the attribute value for the first attribute found with the specified namespace and local name. If no attribute is found with the name then add it.


setAttr

public final void setAttr(java.lang.String name,
                          java.lang.String value)
Set the attribute value for the first attribute found with the specified name. If no attribute is found with the name then add it.


setAttr

public final void setAttr(int index,
                          java.lang.String value)
Set the attribute value at the specified index.


addAttr

public final XElem addAttr(java.lang.String name,
                           java.lang.String value)
Add the specified attribute name value pair using the null namespace.

Returns:
this

addAttr

public final XElem addAttr(XNs ns,
                           java.lang.String name,
                           java.lang.String value)
Add the specified attribute name value pair.

Returns:
this

removeAttr

public final void removeAttr(XNs ns,
                             java.lang.String name)
Remove the first attribute with the specified namespace and local name.


removeAttr

public final void removeAttr(java.lang.String name)
Remove the first attribute with the specified name in the null namespace.


removeAttr

public final void removeAttr(int index)
Remove the attribute at the specified index.


clearAttr

public final void clearAttr()
Clear the attribute list to a count of 0.


contentSize

public final int contentSize()
Get the number of XContent children of this element.


content

public final XContent content(int index)
Get the XContent child at the specified index.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= contentSize()

content

public final XContent[] content()
Get the array of XContent children for this element.


contentIndex

public int contentIndex(XContent child)
Get the index of the specified content instance (using == operator) or return -1 if the specified content is not a child of this element.


elem

public final XElem elem(int index)
Get the XContent at the specified index cast to a XElem.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= contentSize()

elems

public final XElem[] elems()
Get the array of XElem children for this element.


elems

public final XElem[] elems(XNs ns,
                           java.lang.String name)
Get all the children elements in the specified namespace and with the specified local name.


elems

public final XElem[] elems(XNs ns)
Get all the children elements in the specified namespace.


elems

public final XElem[] elems(java.lang.String name)
Get all the children elements with the specified local name regardless of namespace.


elem

public final XElem elem(XNs ns,
                        java.lang.String name)
Get the first child element in the specified namespace and with the specified local name. If not found then return null.


elem

public final XElem elem(java.lang.String name)
Get the first child element the specified local name regardless of namespace. If not found then return null.


addText

public final XElem addText(java.lang.String txt)
Creates and adds a text descendent.

Returns:
this

text

public XText text()
If the first content child is a XText instance, then return it. Otherwise return null.


text

public final XText text(int index)
Get the XContent at the specified index cast to a XText.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= contentSize()

string

public java.lang.String string()
If the first content child is a XText instance, then return the result of calling XText.string(). Otherwise return null.


addContent

public final XElem addContent(XContent child)
Add the specified content to the end of the content list.

Returns:
this

addContent

public final XElem addContent(int index,
                              XContent child)
Insert the content instance as a child of this element at the specified index.

Returns:
this
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index > contentSize()

replaceContent

public final void replaceContent(int index,
                                 XContent child)
Replace the content instance at the specified index with the new content child.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= contentSize()

removeContent

public final void removeContent(XContent child)
Remove the specified content instance (using == operator).


removeContent

public final void removeContent(int index)
Remove the content child at the specified index.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if index >= contentSize()

clearContent

public final void clearContent()
Get the content children and set content count to 0.


dump

public void dump()
Dump to standard out.


write

public void write(java.io.File file)
           throws java.lang.Exception
Write to the specified File.

Throws:
java.lang.Exception

write

public void write(XWriter out)
Write to the specified XWriter stream with indent of 0.

Specified by:
write in class XContent

write

public void write(XWriter out,
                  int indent)
Write to the specified XWriter stream.


line

public final int line()
Get the line number of this element in the document or 0 if unknown.


copy

public final XElem copy()
Make a new cloned copy of this XElem instance.


toString

public java.lang.String toString()
To string returns the start tag.

Overrides:
toString in class java.lang.Object