| Modifier and Type | Method and Description |
|---|---|
XMLTag |
addAttribute(Attr attr)
Add given attribute to current element
|
XMLTag |
addAttribute(String name,
String value)
Create a new attribute for the current node
|
XMLTag |
addCDATA(CDATASection data)
Add a CDATA note to the current tag
|
XMLTag |
addCDATA(String data)
Add a data node under the current node, and jump to the parent node.
|
XMLTag |
addDocument(Document doc)
Inserts another
Document instance under the current tag |
XMLTag |
addDocument(XMLTag tag)
Inserts another
XMLTag instance under the current tag. |
XMLTag |
addNamespace(String prefix,
String namespaceURI)
Add a namespace to the document
|
XMLTag |
addTag(Element tag)
Inserts a
Element instance and its hierarchy under the current tag |
XMLTag |
addTag(String name)
Create a tag under the current location and use it as the current node
|
XMLTag |
addTag(XMLTag tag)
Inserts another
XMLTag tag hierarchy under the current tag. |
XMLTag |
addText(String text)
Add a text node under the current node, and jump to the parent node.
|
XMLTag |
addText(Text text)
Add a text note to the current tag
|
XMLTag |
delete()
Delete current tag and its childs.
|
XMLTag |
deleteAttribute(String name)
Delete an attribute of the current node.
|
XMLTag |
deleteAttributeIfExists(String name)
Delete an attribute of the current node, if it exists
|
XMLTag |
deleteAttributes()
Delete all existing attributes of current node
|
XMLTag |
deleteChilds()
Delete all existing elements of this node
|
XMLTag |
deletePrefixes()
Remove any prefix and namespaces contained in the tag name, childs and attributes, thus changing namespace and tag name.
|
XMLTag |
duplicate() |
String |
findAttribute(String name)
returns the attribute value of the current node or null if the attribute does not exist
|
String |
findAttribute(String name,
String relativeXpath,
Object... arguments)
Returns the attribute value of the node pointed by given XPath expression or null if the attribute does not exist
|
XMLTag |
forEach(CallBack callBack,
String relativeXpath,
Object... arguments)
Execute an action for each selected tags from the current node.
|
XMLTag |
forEach(String xpath,
CallBack callBack) |
XMLTag |
forEachChild(CallBack callBack)
Execute an action for each child in the current node.
|
static XMLTag |
from(File file) |
static XMLTag |
from(File file,
boolean ignoreNamespaces) |
static XMLTag |
from(File file,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(InputSource source) |
static XMLTag |
from(InputSource source,
boolean ignoreNamespaces) |
static XMLTag |
from(InputStream is) |
static XMLTag |
from(InputStream is,
boolean ignoreNamespaces) |
static XMLTag |
from(InputStream is,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(Node node) |
static XMLTag |
from(Node node,
boolean ignoreNamespaces) |
static XMLTag |
from(Reader reader) |
static XMLTag |
from(Reader reader,
boolean ignoreNamespaces) |
static XMLTag |
from(Reader reader,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(Source source) |
static XMLTag |
from(Source source,
boolean ignoreNamespaces) |
static XMLTag |
from(Source source,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(String xmlData) |
static XMLTag |
from(String xmlData,
boolean ignoreNamespaces) |
static XMLTag |
from(String xmlData,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(URL xmlLocation) |
static XMLTag |
from(URL xmlLocation,
boolean ignoreNamespaces) |
static XMLTag |
from(URL xmlLocation,
boolean ignoreNamespaces,
String encoding) |
static XMLTag |
from(XMLTag tag) |
static XMLTag |
from(XMLTag tag,
boolean ignoreNamespaces) |
static XMLTag |
fromCurrentTag(XMLTag tag,
boolean ignoreNamespaces)
Create another
XMLTag instance from the hierarchy under the current tag. |
String |
getAttribute(String name)
returns the attribute value of the current node
|
String |
getAttribute(String name,
String relativeXpath,
Object... arguments)
Returns the attribute value of the node pointed by given XPath expression
|
String[] |
getAttributeNames() |
String |
getCDATA() |
String |
getCDATA(String relativeXpath,
Object... arguments)
Get the CDATA of a selected node
|
String |
getCDATAorText() |
String |
getCDATAorText(String relativeXpath,
Object... arguments)
Get the text of a sepcific node
|
int |
getChildCount() |
List<Element> |
getChildElement() |
Iterable<XMLTag> |
getChilds()
XMLTag tag = XMLDoc.newDocument(true)
.addRoot("root").addTag("a")
.gotoParent().addTag("b")
.gotoParent().addTag("c")
.gotoRoot();
assertEquals(tag.getCurrentTagName(), "root");
for (XMLTag xmlTag : tag.getChilds()) {
if(xmlTag.getCurrentTagName().equals("b")) {
break;
}
}
assertEquals(tag.getCurrentTagName(), "b"); |
Iterable<XMLTag> |
getChilds(String relativeXpath,
Object... arguments)
Create an iterable object over selected elements.
|
NamespaceContext |
getContext() |
Element |
getCurrentTag() |
String |
getCurrentTagLocation() |
String |
getCurrentTagName() |
XMLTag |
getInnerDocument() |
String |
getInnerText() |
String |
getPefix(String namespaceURI)
Get the prefix of a namespace
|
String[] |
getPefixes(String namespaceURI)
Get all bound prefixes of a namespace
|
String |
getText() |
String |
getText(String relativeXpath,
Object... arguments)
Get the text of a sepcific node
|
String |
getTextOrCDATA() |
String |
getTextOrCDATA(String relativeXpath,
Object... arguments)
Get the text of a sepcific node
|
XMLTag |
gotoChild()
Go to the only child element of the curent node.
|
XMLTag |
gotoChild(int i)
Go to the Nth child of the curent node.
|
XMLTag |
gotoChild(String nodeName)
Go to the child found with given node name
|
XMLTag |
gotoFirstChild()
Go to the first child element of the curent node.
|
XMLTag |
gotoFirstChild(String name)
Go to the first child occurance found having given name
|
XMLTag |
gotoLastChild()
Go to the lastest child element of the curent node.
|
XMLTag |
gotoLastChild(String name)
Go to the last child occurance found having given name
|
XMLTag |
gotoParent()
Go to parent tag.
|
XMLTag |
gotoRoot()
Go to document root tag
|
XMLTag |
gotoTag(String relativeXpath,
Object... arguments)
Go to a specific node
|
boolean |
hasAttribute(String name)
Check wheter current tag contains an atribute
|
boolean |
hasAttribute(String name,
String relativeXpath,
Object... arguments)
Check if targeted tag has an attribute of given name
|
boolean |
hasTag(String relativeXpath,
Object... arguments)
Check if a tag exist in the document
|
static XMLDocBuilder |
newDocument() |
static XMLDocBuilder |
newDocument(boolean ignoreNamespaces) |
Boolean |
rawXpathBoolean(String relativeXpath,
Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.
|
Node |
rawXpathNode(String relativeXpath,
Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.
|
NodeList |
rawXpathNodeSet(String relativeXpath,
Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.
|
Number |
rawXpathNumber(String relativeXpath,
Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.
|
String |
rawXpathString(String relativeXpath,
Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.
|
XMLTag |
renameTo(String newNodeName)
Replace current element name by another name
|
XMLTag |
setAttribute(String name,
String value)
Sets the new value on an existign attribute, and remains on the current tag.
|
XMLTag |
setAttribute(String name,
String value,
String relativeXpath,
Object... arguments)
Sets the new value on a targetted node's attribute, and remains on the current tag.
|
XMLTag |
setAttributeIfExist(String name,
String value)
Sets the new value on an attribute, and remains on the current tag.
|
XMLTag |
setAttributeIfExist(String name,
String value,
String relativeXpath,
Object... arguments)
Sets the new value on a targetted node's attribute, and remains on the current tag.
|
XMLTag |
setCDATA(String data)
Set the cdata in the current node.
|
XMLTag |
setCDATA(String data,
String relativeXpath,
Object... arguments)
Set the cdata in the targetted node.
|
XMLTag |
setCDATAIfExist(String data,
String relativeXpath,
Object... arguments)
Set the cdata in the targetted node.
|
XMLTag |
setText(String text)
Set the text in the current node.
|
XMLTag |
setText(String text,
String relativeXpath,
Object... arguments)
Set the text in the targetted node.
|
XMLTag |
setTextIfExist(String text,
String relativeXpath,
Object... arguments)
Set the text in the targetted node.
|
byte[] |
toBytes() |
byte[] |
toBytes(String encoding) |
Document |
toDocument() |
OutputStream |
toOutputStream() |
OutputStream |
toOutputStream(String encoding) |
Result |
toResult() |
XMLTag |
toResult(Result out)
Converts this document to the result provided
|
XMLTag |
toResult(Result out,
String encoding)
Converts this document to the result provided, overriding default encoding of xml document
|
Result |
toResult(String encoding) |
Source |
toSource() |
XMLTag |
toStream(OutputStream out)
Write this document to a stream
|
XMLTag |
toStream(OutputStream out,
String encoding)
Write this document to a stream
|
XMLTag |
toStream(Writer out)
Write this document to a stream
|
XMLTag |
toStream(Writer out,
String encoding)
Write this document to a stream
|
String |
toString() |
String |
toString(String encoding) |
Writer |
toWriter() |
Writer |
toWriter(String encoding) |
ValidationResult |
validate(Source... schemas)
Validate this document against specifief schemas
|
ValidationResult |
validate(URL... schemaLocations)
Validate this document against specifief schemas
|
public NamespaceContext getContext()
getContext in interface XMLTagpublic boolean hasAttribute(String name)
XMLTaghasAttribute in interface XMLTagname - Attribute namepublic boolean hasAttribute(String name, String relativeXpath, Object... arguments)
XMLTaghasAttribute in interface XMLTagname - the name of the attributerelativeXpath - XPath that target the tagarguments - optional arguments of xpath expression. Uses String.format() to build XPath expression.public boolean hasTag(String relativeXpath, Object... arguments)
XMLTagpublic XMLTag forEachChild(CallBack callBack)
XMLTagforEachChild in interface XMLTagcallBack - Callback method to run after the current tag of the document has changed to a childpublic XMLTag forEach(CallBack callBack, String relativeXpath, Object... arguments)
XMLTagforEach in interface XMLTagcallBack - Callback method to run after the current tag of the document has changed to a childrelativeXpath - XXath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.public String rawXpathString(String relativeXpath, Object... arguments)
XMLTagrawXpathString in interface XMLTagrelativeXpath - The XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.STRING return typepublic Number rawXpathNumber(String relativeXpath, Object... arguments)
XMLTagrawXpathNumber in interface XMLTagrelativeXpath - The XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NUMBER return typepublic Boolean rawXpathBoolean(String relativeXpath, Object... arguments)
XMLTagrawXpathBoolean in interface XMLTagrelativeXpath - The XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.BOOLEAN return typepublic Node rawXpathNode(String relativeXpath, Object... arguments)
XMLTagrawXpathNode in interface XMLTagrelativeXpath - The XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NODE return typepublic NodeList rawXpathNodeSet(String relativeXpath, Object... arguments)
XMLTagrawXpathNodeSet in interface XMLTagrelativeXpath - The XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NODESET return typepublic String getPefix(String namespaceURI)
XMLTagpublic String[] getPefixes(String namespaceURI)
XMLTaggetPefixes in interface XMLTagnamespaceURI - The URI of the namespacepublic XMLTag addNamespace(String prefix, String namespaceURI)
XMLTagaddNamespace in interface XMLTagprefix - The prefix of the namespacenamespaceURI - The URI of the namespacepublic XMLTag addDocument(XMLTag tag)
XMLTagXMLTag instance under the current tag. The whole document will be inserted.addDocument in interface XMLTagtag - The XMLTag instance to insertpublic XMLTag addDocument(Document doc)
XMLTagDocument instance under the current tagaddDocument in interface XMLTagdoc - The Document instance to insertpublic XMLTag addTag(XMLTag tag)
XMLTagXMLTag tag hierarchy under the current tag. Only the current tag of the given document
will be inserted with its hierarchy, not the whole document.public XMLTag addTag(Element tag)
XMLTagElement instance and its hierarchy under the current tagpublic XMLTag addTag(String name)
XMLTagpublic XMLTag addAttribute(String name, String value)
XMLTagaddAttribute in interface XMLTagname - Name of the attribute to addvalue - value of the attribute to addpublic XMLTag addAttribute(Attr attr)
XMLTagaddAttribute in interface XMLTagattr - The attribute to insertpublic XMLTag addText(String text)
XMLTagaddTag("name").addText("Bob")addTag("sex").addText("M")addTag("age").addText("30")
<name>Bob</name><sex>M</sex><age>30</age>public XMLTag addText(Text text)
XMLTagpublic XMLTag addCDATA(String data)
XMLTagaddTag("name").addCDATA("Bob")addTag("sex").addCDATA("M")addTag("age").addCDATA("30")
<name><![CDATA[Bob]]></name><sex><![CDATA[M]]></sex><age><![CDATA[30]]></age>public XMLTag addCDATA(CDATASection data)
XMLTagpublic XMLTag delete()
XMLTagpublic XMLTag deleteChilds()
XMLTagdeleteChilds in interface XMLTagpublic XMLTag deleteAttributes()
XMLTagdeleteAttributes in interface XMLTagpublic XMLTag deleteAttribute(String name)
XMLTagdeleteAttribute in interface XMLTagname - attribute namepublic XMLTag deleteAttributeIfExists(String name)
XMLTagdeleteAttributeIfExists in interface XMLTagname - attribute namepublic XMLTag renameTo(String newNodeName)
XMLTagpublic XMLTag deletePrefixes()
XMLTagdeletePrefixes in interface XMLTagpublic XMLTag getInnerDocument()
getInnerDocument in interface XMLTagpublic String getInnerText()
getInnerText in interface XMLTagpublic XMLTag gotoParent()
XMLTaggotoParent in interface XMLTagpublic XMLTag gotoChild()
XMLTagpublic XMLTag gotoChild(int i)
XMLTagpublic XMLTag gotoChild(String nodeName)
XMLTagpublic XMLTag gotoFirstChild() throws XMLDocumentException
XMLTaggotoFirstChild in interface XMLTagXMLDocumentException - If the current node has no child at allpublic XMLTag gotoFirstChild(String name) throws XMLDocumentException
XMLTaggotoFirstChild in interface XMLTagname - Name of the child to go atXMLDocumentException - If the current node has no child at allpublic XMLTag gotoLastChild() throws XMLDocumentException
XMLTaggotoLastChild in interface XMLTagXMLDocumentException - If the current node has no child at allpublic XMLTag gotoLastChild(String name) throws XMLDocumentException
XMLTaggotoLastChild in interface XMLTagname - Name of the child to go atXMLDocumentException - If the current node has no child at allpublic XMLTag gotoTag(String relativeXpath, Object... arguments)
XMLTagpublic Element getCurrentTag()
getCurrentTag in interface XMLTagpublic int getChildCount()
getChildCount in interface XMLTagpublic Iterable<XMLTag> getChilds()
XMLTag
XMLTag tag = XMLDoc.newDocument(true)
.addRoot("root").addTag("a")
.gotoParent().addTag("b")
.gotoParent().addTag("c")
.gotoRoot();
assertEquals(tag.getCurrentTagName(), "root");
for (XMLTag xmlTag : tag.getChilds()) {
if(xmlTag.getCurrentTagName().equals("b")) {
break;
}
}
assertEquals(tag.getCurrentTagName(), "b");
XMLTag tag = XMLDoc.newDocument(true)
.addRoot("root").addTag("a")
.gotoParent().addTag("b")
.gotoParent().addTag("c")
.gotoRoot();
assertEquals(tag.getCurrentTagName(), "root");
for (XMLTag xmlTag : tag.getChilds()) {
System.out.println(xmlTag.getCurrentTagName());
}
assertEquals(tag.getCurrentTagName(), "root");public Iterable<XMLTag> getChilds(String relativeXpath, Object... arguments)
XMLTagpublic List<Element> getChildElement()
getChildElement in interface XMLTagpublic String getCurrentTagName()
getCurrentTagName in interface XMLTagpublic String getCurrentTagLocation()
getCurrentTagLocation in interface XMLTagpublic String getAttribute(String name)
XMLTaggetAttribute in interface XMLTagname - attribute namepublic String findAttribute(String name)
XMLTagfindAttribute in interface XMLTagname - attribute namepublic String getAttribute(String name, String relativeXpath, Object... arguments)
XMLTaggetAttribute in interface XMLTagname - attribute namerelativeXpath - XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.public String findAttribute(String name, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagfindAttribute in interface XMLTagname - attribute namerelativeXpath - XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - targetted node does not exist or XPath expression is invalidpublic String[] getAttributeNames()
getAttributeNames in interface XMLTagpublic String getText(String relativeXpath, Object... arguments)
XMLTagpublic String getText()
public String getTextOrCDATA()
getTextOrCDATA in interface XMLTagpublic String getTextOrCDATA(String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTaggetTextOrCDATA in interface XMLTagrelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is not valid or if the node does not existpublic String getCDATAorText()
getCDATAorText in interface XMLTagpublic String getCDATAorText(String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTaggetCDATAorText in interface XMLTagrelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is not valid or if the node does not existpublic String getCDATA(String relativeXpath, Object... arguments)
XMLTagpublic String getCDATA()
public Document toDocument()
toDocument in interface XMLTagpublic Source toSource()
public String toString()
public byte[] toBytes()
public byte[] toBytes(String encoding)
public XMLTag toStream(OutputStream out)
XMLTagpublic XMLTag toStream(OutputStream out, String encoding)
XMLTagpublic XMLTag toStream(Writer out)
XMLTagpublic XMLTag toStream(Writer out, String encoding)
XMLTagpublic Result toResult()
public OutputStream toOutputStream()
toOutputStream in interface XMLTagpublic OutputStream toOutputStream(String encoding)
toOutputStream in interface XMLTagencoding - The new encodingpublic Writer toWriter()
public XMLTag toResult(Result out)
XMLTagpublic XMLTag toResult(Result out, String encoding)
XMLTagpublic ValidationResult validate(Source... schemas)
XMLTagpublic ValidationResult validate(URL... schemaLocations)
XMLTagpublic XMLTag duplicate()
public XMLTag setText(String text)
XMLTaggotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")
<name>Bob</name><sex>M</sex><age>30</age>public XMLTag setText(String text, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetText in interface XMLTagtext - text to put under this noderelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is invalid or if the node does not existpublic XMLTag setTextIfExist(String text, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetTextIfExist in interface XMLTagtext - text to put under this noderelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is invalidpublic XMLTag setCDATA(String data)
XMLTaggotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")
<name>Bob</name><sex>M</sex><age>30</age>public XMLTag setCDATA(String data, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetCDATA in interface XMLTagdata - text to put under this node in a cdata sectionrelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is invalid or if the node does not existpublic XMLTag setCDATAIfExist(String data, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetCDATAIfExist in interface XMLTagdata - text to put under this node in a cdata sectionrelativeXpath - XPath expression that select the nodearguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - If the XPath expression is invalidpublic XMLTag setAttribute(String name, String value) throws XMLDocumentException
XMLTagsetAttribute in interface XMLTagname - attribute namevalue - new attribute'svalueXMLDocumentException - If the attribute does not existpublic XMLTag setAttributeIfExist(String name, String value)
XMLTagsetAttributeIfExist in interface XMLTagname - attribute namevalue - new attribute valuepublic XMLTag setAttribute(String name, String value, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetAttribute in interface XMLTagname - attribute namevalue - new attribute's valuerelativeXpath - XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - Attribute does not exist, targetted node does not exit, or XPath expression is invalidpublic XMLTag setAttributeIfExist(String name, String value, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTagsetAttributeIfExist in interface XMLTagname - attribute namevalue - new attribute's valuerelativeXpath - XPath expressionarguments - facultative Xpath expression arguments. Uses String.format() to build XPath expression.XMLDocumentException - XPath expression is invalid or targetted node does not existpublic static XMLDocBuilder newDocument(boolean ignoreNamespaces)
public static XMLTag from(InputSource source, boolean ignoreNamespaces)
public static XMLTag from(InputStream is, boolean ignoreNamespaces)
public static XMLTag from(InputStream is, boolean ignoreNamespaces, String encoding)
public static XMLDocBuilder newDocument()
public static XMLTag from(InputSource source)
public static XMLTag from(InputStream is)
public static XMLTag fromCurrentTag(XMLTag tag, boolean ignoreNamespaces)
XMLTag instance from the hierarchy under the current tag. The current tag becomes the root tag.tag - The current XML Tag positionned to the new root tagignoreNamespaces - Wheter to build a namespace aware documentCopyright © 2008–2014 Mycila. All rights reserved.