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,
boolean ignoreNamespaces) |
static XMLTag |
from(InputSource source,
boolean ignoreNamespaces) |
static XMLTag |
from(InputStream is,
boolean ignoreNamespaces) |
static XMLTag |
from(Node node,
boolean ignoreNamespaces) |
static XMLTag |
from(Reader reader,
boolean ignoreNamespaces) |
static XMLTag |
from(Source source,
boolean ignoreNamespaces) |
static XMLTag |
from(String xmlData,
boolean ignoreNamespaces) |
static XMLTag |
from(URL xmlLocation,
boolean ignoreNamespaces) |
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(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 XMLTag
public boolean hasAttribute(String name)
XMLTag
hasAttribute
in interface XMLTag
name
- Attribute namepublic boolean hasAttribute(String name, String relativeXpath, Object... arguments)
XMLTag
hasAttribute
in interface XMLTag
name
- 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)
XMLTag
public XMLTag forEachChild(CallBack callBack)
XMLTag
forEachChild
in interface XMLTag
callBack
- Callback method to run after the current tag of the document has changed to a childpublic XMLTag forEach(CallBack callBack, String relativeXpath, Object... arguments)
XMLTag
forEach
in interface XMLTag
callBack
- 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)
XMLTag
rawXpathString
in interface XMLTag
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.STRING
return typepublic Number rawXpathNumber(String relativeXpath, Object... arguments)
XMLTag
rawXpathNumber
in interface XMLTag
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NUMBER
return typepublic Boolean rawXpathBoolean(String relativeXpath, Object... arguments)
XMLTag
rawXpathBoolean
in interface XMLTag
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.BOOLEAN
return typepublic Node rawXpathNode(String relativeXpath, Object... arguments)
XMLTag
rawXpathNode
in interface XMLTag
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NODE
return typepublic NodeList rawXpathNodeSet(String relativeXpath, Object... arguments)
XMLTag
rawXpathNodeSet
in interface XMLTag
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.XPathConstants.NODESET
return typepublic String getPefix(String namespaceURI)
XMLTag
public String[] getPefixes(String namespaceURI)
XMLTag
getPefixes
in interface XMLTag
namespaceURI
- The URI of the namespacepublic XMLTag addNamespace(String prefix, String namespaceURI)
XMLTag
addNamespace
in interface XMLTag
prefix
- The prefix of the namespacenamespaceURI
- The URI of the namespacepublic XMLTag addDocument(XMLTag tag)
XMLTag
XMLTag
instance under the current tag. The whole document will be inserted.addDocument
in interface XMLTag
tag
- The XMLTag
instance to insertpublic XMLTag addDocument(Document doc)
XMLTag
Document
instance under the current tagaddDocument
in interface XMLTag
doc
- The Document
instance to insertpublic XMLTag addTag(XMLTag tag)
XMLTag
XMLTag
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)
XMLTag
Element
instance and its hierarchy under the current tagpublic XMLTag addTag(String name)
XMLTag
public XMLTag addAttribute(String name, String value)
XMLTag
addAttribute
in interface XMLTag
name
- Name of the attribute to addvalue
- value of the attribute to addpublic XMLTag addAttribute(Attr attr)
XMLTag
addAttribute
in interface XMLTag
attr
- The attribute to insertpublic XMLTag addText(String text)
XMLTag
addTag("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)
XMLTag
public XMLTag addCDATA(String data)
XMLTag
addTag("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)
XMLTag
public XMLTag delete()
XMLTag
public XMLTag deleteChilds()
XMLTag
deleteChilds
in interface XMLTag
public XMLTag deleteAttributes()
XMLTag
deleteAttributes
in interface XMLTag
public XMLTag deleteAttribute(String name)
XMLTag
deleteAttribute
in interface XMLTag
name
- attribute namepublic XMLTag deleteAttributeIfExists(String name)
XMLTag
deleteAttributeIfExists
in interface XMLTag
name
- attribute namepublic XMLTag renameTo(String newNodeName)
XMLTag
public XMLTag deletePrefixes()
XMLTag
deletePrefixes
in interface XMLTag
public XMLTag getInnerDocument()
getInnerDocument
in interface XMLTag
public String getInnerText()
getInnerText
in interface XMLTag
public XMLTag gotoParent()
XMLTag
gotoParent
in interface XMLTag
public XMLTag gotoChild()
XMLTag
public XMLTag gotoChild(int i)
XMLTag
public XMLTag gotoChild(String nodeName)
XMLTag
public XMLTag gotoFirstChild() throws XMLDocumentException
XMLTag
gotoFirstChild
in interface XMLTag
XMLDocumentException
- If the current node has no child at allpublic XMLTag gotoFirstChild(String name) throws XMLDocumentException
XMLTag
gotoFirstChild
in interface XMLTag
name
- Name of the child to go atXMLDocumentException
- If the current node has no child at allpublic XMLTag gotoLastChild() throws XMLDocumentException
XMLTag
gotoLastChild
in interface XMLTag
XMLDocumentException
- If the current node has no child at allpublic XMLTag gotoLastChild(String name) throws XMLDocumentException
XMLTag
gotoLastChild
in interface XMLTag
name
- Name of the child to go atXMLDocumentException
- If the current node has no child at allpublic XMLTag gotoTag(String relativeXpath, Object... arguments)
XMLTag
public Element getCurrentTag()
getCurrentTag
in interface XMLTag
public int getChildCount()
getChildCount
in interface XMLTag
public 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)
XMLTag
public List<Element> getChildElement()
getChildElement
in interface XMLTag
public String getCurrentTagName()
getCurrentTagName
in interface XMLTag
public String getCurrentTagLocation()
getCurrentTagLocation
in interface XMLTag
public String getAttribute(String name)
XMLTag
getAttribute
in interface XMLTag
name
- attribute namepublic String findAttribute(String name)
XMLTag
findAttribute
in interface XMLTag
name
- attribute namepublic String getAttribute(String name, String relativeXpath, Object... arguments)
XMLTag
getAttribute
in interface XMLTag
name
- 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
XMLTag
findAttribute
in interface XMLTag
name
- 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 XMLTag
public String getText(String relativeXpath, Object... arguments)
XMLTag
public String getText()
public String getTextOrCDATA()
getTextOrCDATA
in interface XMLTag
public String getTextOrCDATA(String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTag
getTextOrCDATA
in interface XMLTag
relativeXpath
- 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 XMLTag
public String getCDATAorText(String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTag
getCDATAorText
in interface XMLTag
relativeXpath
- 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)
XMLTag
public String getCDATA()
public Document toDocument()
toDocument
in interface XMLTag
public Source toSource()
public String toString()
public byte[] toBytes()
public byte[] toBytes(String encoding)
public XMLTag toStream(OutputStream out)
XMLTag
public XMLTag toStream(OutputStream out, String encoding)
XMLTag
public XMLTag toStream(Writer out)
XMLTag
public XMLTag toStream(Writer out, String encoding)
XMLTag
public Result toResult()
public OutputStream toOutputStream()
toOutputStream
in interface XMLTag
public OutputStream toOutputStream(String encoding)
toOutputStream
in interface XMLTag
encoding
- The new encodingpublic Writer toWriter()
public XMLTag toResult(Result out)
XMLTag
public XMLTag toResult(Result out, String encoding)
XMLTag
public ValidationResult validate(Source... schemas)
XMLTag
public ValidationResult validate(URL... schemaLocations)
XMLTag
public XMLTag duplicate()
public XMLTag setText(String text)
XMLTag
gotoChild("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
XMLTag
setText
in interface XMLTag
text
- 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
XMLTag
setTextIfExist
in interface XMLTag
text
- 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)
XMLTag
gotoChild("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
XMLTag
setCDATA
in interface XMLTag
data
- 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
XMLTag
setCDATAIfExist
in interface XMLTag
data
- 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
XMLTag
setAttribute
in interface XMLTag
name
- attribute namevalue
- new attribute'svalueXMLDocumentException
- If the attribute does not existpublic XMLTag setAttributeIfExist(String name, String value)
XMLTag
setAttributeIfExist
in interface XMLTag
name
- attribute namevalue
- new attribute valuepublic XMLTag setAttribute(String name, String value, String relativeXpath, Object... arguments) throws XMLDocumentException
XMLTag
setAttribute
in interface XMLTag
name
- 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
XMLTag
setAttributeIfExist
in interface XMLTag
name
- 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 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–2016 Mathieu Carbou. All rights reserved.