|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IXml
<boat color="red" weight="1200"> The greatest little boat in the world <sail area="48"> really strong nylon <thread thickness="2" > doesn't stretch much </thread> </sail> <anchor material="iron"/> </boat>The example is comprised of one outer element whose name is "boat". It has two attributes named color and weight which have respective values of "red" and "1200". The boat element has one text child of "The greatest little boat in the world" and two element children named sail and anchor.
XmlUtil
for documentation on methods that can parse strings of XML and HTML
into IXml objects.
,
XmlTreeWalker
Method Summary | |
---|---|
void |
addCDATASection(java.lang.String data)
Create a new CDATA node and set its text to the argument. |
void |
addChildElement(IXml xml)
Moves the specified element in the argument from its original parent to become the new last child of this element. |
IXml |
addChildElement(java.lang.String name)
Create a new element with a name of the argument. |
IXml |
addChildElement(java.lang.String localname,
java.lang.String prefix,
java.lang.String namespaceURI)
Add a child element to this element, with the specified localname, prefix (optionally null) and namespace URI See also IXml.addChildElement(String name) NS-Unaware method |
IXml |
addChildWithText(java.lang.String name,
java.lang.String text)
Similar to addChildElement. |
void |
addText(java.lang.String value)
Creates a text node having the text of the first argument and makes it the new last child of this. |
IXml |
cloneElement()
Creates a new unparented node whose attributes are the same as this node's attributes. |
void |
copyContent(IXml xml)
Copy all the children of the xml argument (text and elements) and add them as children of this. |
IXml |
createPath(java.lang.String path)
Ensures that the specified path of elements exist, creating elements if they do not. |
void |
declareNamespace(java.lang.String prefix,
java.lang.String namespaceURI)
Declare a namespace prefix to URI mapping on this element. |
void |
declareNamespaces(java.util.Map mappings)
Declare a set of namespace prefix to URI mappings on this element. |
IXml |
findElement(java.lang.String path)
Finds the specified element under this using an xpath like notation. |
java.lang.String |
getAttribute(java.lang.String name)
Returns the value of the named attribute, or an empty string if the attribute does not exist on this. |
java.lang.String |
getAttribute(java.lang.String localName,
java.lang.String namespaceURI)
Get the value of the attribute on this element with this specified localname and associated with the specified namespace URI, without requiring prior knowledge of what ns prefix if any may be in use on the actual attribute. |
java.util.Map |
getAttributes()
Returns the attributes of this element as a name-value pair Map. |
java.util.List |
getChildren()
Returns a list of all of the children elements of this element. |
java.util.List |
getChildren(java.lang.String name)
Returns a list of all of the element children of this element who's name matches the specified name. |
java.util.List |
getChildren(java.lang.String localName,
java.lang.String namespaceURI)
Get a (possibly empty) List of direct children elements of this element matching the specified localname and namespace URI, without requiring prior knowledge of what if any namespace prefix may be in use for the element. |
IXml |
getFirstChildElement()
Returns the first child of this element |
java.lang.String |
getLocalName()
Get the local name (without prefix) of this XML Element. |
java.lang.String |
getName()
Returns the name of the XML tag for this element |
java.lang.String |
getNamespacePrefix()
Get the namespace prefix associated with this XML Element, or empty String. |
java.lang.String |
getNamespaceURI()
Get the namespace URI associated with this XML Element or null ONLY supported for XML created via namespace aware XML APIs and/or parser (eg, XmlUtil.parseXml(String), XmlUtil.parseXml(Reader), or XmlUtil.createXml(Object source) where source is JDOM or DOM object) Will return null if used on IXml element created with older namespace- unaware APIs such as XmlUtil.create("a:b") or IXml.addChild("y:z"); even though those older APIs "appear" to be creating a namespace qualified name. |
IXml |
getNextSiblingElement()
Returns the next sibling of this element or null if this is the last child of its parent. |
IXml |
getParentElement()
Gets the parent element of this element. |
IXml |
getPreviousSiblingElement()
Returns the previous sibling of this element or null if this is the first child of its parent. |
java.lang.String |
getText()
Returns the text from the first child text node of this element. |
java.lang.String |
getText(java.lang.String path)
Finds the specified element and gets its first text value using an xpath like notation. |
java.lang.Object |
getUserObject()
Returns the user object associated with this element. |
java.lang.String |
getValueOf(java.lang.String path)
Returns the string value of the specified XSL Value-Of like expression. |
void |
insertBefore(IXml newChild,
IXml refChild)
Insert an existing node before the specified child. |
void |
moveContent(IXml xml)
Remove the children from the IXml argument and add them to this IXml object. |
void |
removeAttribute(java.lang.String name)
Removes the named attribute. |
void |
removeChildElement(IXml child)
Removes the specified immediate child and makes it parentless. |
void |
removeChildElement(java.lang.String child)
Removes the named immediate child from this element and makes the removed child parentless. |
void |
removeChildren()
Removes all of the children from this element. |
void |
replaceChild(IXml newChild,
IXml oldChild)
Replace the old child with the new child. |
void |
setAttribute(java.lang.String name,
java.lang.String value)
Assigns or modifies the value of the specified attribute. |
void |
setAttribute(java.lang.String localName,
java.lang.String prefix,
java.lang.String namespaceURI,
java.lang.String value)
Set an attribute with the specified localname, prefix and namespaceURI. |
void |
setName(java.lang.String name)
Renames this element with the specified name. |
void |
setText(java.lang.String value)
Sets the first text node value for this element. |
void |
setText(java.lang.String path,
java.lang.String value)
Set the first text node value for the specified element path and create the path if it does not exist. |
void |
setUserObject(java.lang.Object userObject)
The IXml interface allows you to associate an arbitrary Java object with an element. |
java.lang.String |
toString()
Creates and returns a string of the IXml object in this. |
void |
writeHtml(java.io.Writer out)
Writes out the XML data as proper HTML to the specified writer. |
void |
writeXml(java.io.Writer out)
Writes out the XML data to the specified Writer character stream. |
Method Detail |
---|
void addCDATASection(java.lang.String data)
data
- The CDATA to add.addText(java.lang.String)
IXml example3 = XmlUtil.create("plane"); example3.addCDATASection("some < & >'s"); example3.getText(); => "some < & >'s"
void addChildElement(IXml xml)
xml
- The IXml to add as an immediate child.addChildWithText
Move the argument into example1. example1.addChildElement(XmlUtil.create("motor")); Put a copy of the argument into example1. example1.addChildElement(an_elt.cloneElement());
IXml addChildElement(java.lang.String name)
name
- The name of the new immediate child to create.
addChildWithText
example1.addChildElement("motor"); example1.findElement("motor"); => the new element
IXml addChildElement(java.lang.String localname, java.lang.String prefix, java.lang.String namespaceURI)
localname
- for the new child elementprefix
- associated with the namespace for the child elem (or null)namespaceURI
- for the namespace associated with the child
XmlDOMException
- if localname contains a colon ':' characterIXml addChildWithText(java.lang.String name, java.lang.String text)
name
- The name of the new immediate child element to create.text
- The text of the new child.
addChildElement
example1.addChildWithText("motor", "out of gas"); example1.getText("boat/motor"); => "out of gas"
void addText(java.lang.String value)
value
- The text to addsetText
,
getText
IXml example2 = XmlUtil.create("car"); example2.addText("rent-a-wreck reject"); example2.getText(); => "rent-a-wreck reject" example2.addText(" but still runs"); example2.getText(); => "rent-a-wreck reject but still runs" example2.addChildElement("radio"); example2.addText(" downhill"); example2.getText(); => "rent-a-wreck reject but still runs" Note that we did not get "rent-a-wreck reject but still runs downhill" because of the interspersed "radio" child element.
IXml cloneElement()
example1.cloneElement();
void copyContent(IXml xml)
xml
- The element to be copied.moveContent
example1.copyContent(some_ixml_object_to_copy);
IXml createPath(java.lang.String path)
path
- The element path to build up
Below we create an element with name "foo", child "bar" and grandchild "new". foo becomes a new last child of "this". The bottom element, "new", is returned. example1.createPath("foo/bar/new"); leaves us with a modified example1 of: <boat ...> ... <foo> <bar> <new/> </bar> </foo> </boat>
void declareNamespace(java.lang.String prefix, java.lang.String namespaceURI)
prefix
- namespaceURI
-
XmlDOMException
- if prefix or namespaceURI arguments are nullvoid declareNamespaces(java.util.Map mappings)
mappings
- java.util.Map of prefix to namespace URI mappings
XmlDOMException
- if prefix or namespaceURI arguments are nullIXml findElement(java.lang.String path)
Find the second instance of the child element of x2 that has a name of x3. IXml xmlTempData = xmlData.findElement("x1/x2/x3[1]"); Find the first instance of an element named x3 beneath x2 where the text value equals "y3". IXml xmlTempData = xmlData.findElement("x1/x2/[x3=y3]"); Find the instance of x3 beneath x2 where the "name" attribute has a value of "junk". IXml xmlTempData = xmlData.findElement("x1/x2/x3[@name=junk]"); Find the instance of x3 two levels below x1 where the second level element is unknown. IXml xmlTempData = xmlData.findElement("x1/*[1]/x3"); Find the parent of x3 where a name attribute value equals "junk". This example will return the element named x2. IXml xmlTempData = xmlData.findElement("x1/x2/x3[@name=junk]/.."); Find the instance of x2 that has an x1 parent and an x3 child whose child text value equals "junk". Note the use of single quotes which must be used to not confuse the string "junk" with the whole argument that uses double quotes for delimiters. IXml xmlTempData = xmlData.findElement("x1/x2[x3='junk']"); Find the instance of x3 that is a child of an x1 instance. The x1 instance to use is distinguished from other possible x1 instances because it is the first x1 instance that has an x2 child whose child text value equals "junk". Here x2 and x3 are siblings, both of which are children of x1. IXml xmlTempData = xmlData.findElement("//x1[x2='junk']/x3"); Find the first instance of x2 that is a descendant of x1. x2 can be an immediate child of x1 or at any level beneath it. IXml xmlTempData = xmlData.findElement("x1//x2"); Note: The <i>begin</i> and <i>end</i> bracket characters ([ ]) are special characters that must not be used in the data section of the specified path. Warning: Using complex filters may not be as fast as using simple '/' notation(i.e. x1/x2/x3)
java.lang.String getAttribute(java.lang.String name)
name
- The name of the attribute to get
getAttributes
,
setAttribute
,
removeAttribute
example1.getAttribute("color"); => "red"
java.lang.String getAttribute(java.lang.String localName, java.lang.String namespaceURI)
localName
- of the attributenamespaceURI
- associated with the attribute
java.util.Map getAttributes()
getAttribute
,
setAttribute
Map my_atts = example1.getAttributes(); my_atts.get("color"); => "red"
java.util.List getChildren()
example1.getChildren().get(0) => the first child element of "this".
java.util.List getChildren(java.lang.String name)
example1.getChildren("sail").size() => 1
java.util.List getChildren(java.lang.String localName, java.lang.String namespaceURI)
localName
- of the child(ren)namespaceURI
- associated with the attribute
IXml getFirstChildElement()
getPreviousSiblingElement
,
getNextSiblingElement
example1.getFirstChildElement().getName() => "sail"
java.lang.String getLocalName()
java.lang.String getName()
example1.getName(); => "boat"
java.lang.String getNamespacePrefix()
java.lang.String getNamespaceURI()
IXml getNextSiblingElement()
getFirstChildElement
,
getPreviousSiblingElement
example1.getFirstChildElement().getNextSiblingElement().getName() => "anchor"
IXml getParentElement()
element1.getParentElement(); => null
IXml getPreviousSiblingElement()
getFirstChildElement
,
getNextSiblingElement
example1.getFirstChildElement().getPreviousSiblingElement() => null
java.lang.String getText()
setText
example1.getText(); => "The greatest little boat in the world"
java.lang.String getText(java.lang.String path)
findElement
example1.getText("sail"); => "really strong nylon" example1.getText("sail/thread"); => "doesn't stretch much"
java.lang.Object getUserObject()
setUserObject
example1.setUserObject(new Integer(486)); example1.getUserObject().intValue(); => 486
java.lang.String getValueOf(java.lang.String path)
path
- The expression to be evaluated.
findElement
example1.getValueOf("sail"); => "really strong nylon" example1.getValueOf("sail/@area"); => "48" example1.getValueOf("sail/thread"); => "doesn't stretch much"
void insertBefore(IXml newChild, IXml refChild)
newChild
- The new element to add.refChild
- The reference element to insert before.replaceChild
example1.insertBefore(XmlUtil.create("mast"), example1.getFirstChildElement()); example1.getFirstChildElement(); => the new "mast" element.
void moveContent(IXml xml)
xml
- The IXml node to get the children from.copyContent
example1.moveContent(some_ixml_object_to_copy);
void removeAttribute(java.lang.String name)
name
- The name of the attribute to removegetAttribute
,
setAttribute
example1.removeAttribute("weight"); example1.getAttribute("weight"); => ""
void removeChildElement(IXml child)
child
- The immediate child to be removed.IXml firstKid = example1.getFirstChildElement(); example1.removeChildElement(firstKid); example1.getFirstChildElement(); => the element named "anchor".
void removeChildElement(java.lang.String child)
child
- The name of the immediate child to be removed.example1.removeChildElement("sail"); example1.getFirstChildElement(); => the element named "anchor".
void removeChildren()
removeChildElement
example1.removeChildren(); example1.getFirstChildElement(); => null
void replaceChild(IXml newChild, IXml oldChild)
newChild
- The new element to add.oldChild
- The reference element to be replaced.insertBefore
example1.replaceChild(XmlUtil.create("mast"), example1.getFirstChildElement()); example1.getFirstChildElement(); => the "mast" element. Now the "sail" child of example1 is gone.
void setAttribute(java.lang.String name, java.lang.String value)
name
- The name of the attribute to setvalue
- The attribute valuegetAttribute
,
removeAttribute
example1.setAttribute("color", "blue"); example1.getAttribute("color"); => "blue"
void setAttribute(java.lang.String localName, java.lang.String prefix, java.lang.String namespaceURI, java.lang.String value)
localName
- of the attributeprefix
- associated with the namespacenamespaceURI
- associated with the attributevalue
-
XmlDOMException
- if prefix==null && namespaceURI != nullvoid setName(java.lang.String name)
name
- The new element name.example1.setName("car"); example1.getName(); => "car"
void setText(java.lang.String value)
value
- The text value to setgetText
example1.setText("A leaky bathtub"); example1.getText(); => "A leaky bathtub"
void setText(java.lang.String path, java.lang.String value)
path
- The path of the element to set the text onvalue
- The text value to setgetText
,
findElement
,
createPath
example1.setText("sail/thread", "ripped rags"); example1.getText("sail/thread"); => "ripped rags"
void setUserObject(java.lang.Object userObject)
userObject
- object to be associated.getUserObject
example1.setUserObject(new Integer(486)); example1.getUserObject().intValue(); => 486
java.lang.String toString()
toString
in class java.lang.Object
writeXml(java.io.Writer)
example1.toString() => "<boat ..."
void writeHtml(java.io.Writer out) throws java.io.IOException
out
- The Writer character stream to output to.
java.io.IOException
writeXml
example1.writeHtml(some_writer_stream);
void writeXml(java.io.Writer out) throws java.io.IOException
out
- The Writer to output to.
java.io.IOException
writeHtml
StringWriter sw = new StringWriter(); example1.writeHtml(sw); sw.toString(); => "<boat ...."
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |