Package com.mycila.xmltool
Class XMLDoc
- java.lang.Object
-
- com.mycila.xmltool.XMLDoc
-
-
Field Summary
Fields Modifier and Type Field Description (package private) org.w3c.dom.Element
current
private XMLDocDefinition
definition
-
Constructor Summary
Constructors Constructor Description XMLDoc(XMLDocDefinition definition)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XMLTag
addAttribute(java.lang.String name, java.lang.String value)
Create a new attribute for the current nodeXMLTag
addAttribute(org.w3c.dom.Attr attr)
Add given attribute to current elementXMLTag
addCDATA(java.lang.String data)
Add a data node under the current node, and jump to the parent node.XMLTag
addCDATA(org.w3c.dom.CDATASection data)
Add a CDATA note to the current tagXMLTag
addDocument(XMLTag tag)
Inserts anotherXMLTag
instance under the current tag.XMLTag
addDocument(org.w3c.dom.Document doc)
Inserts anotherDocument
instance under the current tagXMLTag
addNamespace(java.lang.String prefix, java.lang.String namespaceURI)
Add a namespace to the documentXMLTag
addTag(XMLTag tag)
Inserts anotherXMLTag
tag hierarchy under the current tag.XMLTag
addTag(java.lang.String name)
Create a tag under the current location and use it as the current nodeXMLTag
addTag(org.w3c.dom.Element tag)
Inserts aElement
instance and its hierarchy under the current tagXMLTag
addText(java.lang.String text)
Add a text node under the current node, and jump to the parent node.XMLTag
addText(org.w3c.dom.Text text)
Add a text note to the current tagprivate java.util.List<org.w3c.dom.Attr>
attr(org.w3c.dom.Element e)
private java.util.List<org.w3c.dom.Node>
childs(short type)
private java.util.List<org.w3c.dom.Element>
childs(org.w3c.dom.Element e)
XMLTag
delete()
Delete current tag and its childs.XMLTag
deleteAttribute(java.lang.String name)
Delete an attribute of the current node.XMLTag
deleteAttributeIfExists(java.lang.String name)
Delete an attribute of the current node, if it existsXMLTag
deleteAttributes()
Delete all existing attributes of current nodeXMLTag
deleteChilds()
Delete all existing elements of this nodeXMLTag
deletePrefixes()
Remove any prefix and namespaces contained in the tag name, childs and attributes, thus changing namespace and tag name.XMLTag
duplicate()
java.lang.String
findAttribute(java.lang.String name)
returns the attribute value of the current node or null if the attribute does not existjava.lang.String
findAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments)
Returns the attribute value of the node pointed by given XPath expression or null if the attribute does not existXMLTag
forEach(CallBack callBack, java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an action for each selected tags from the current node.XMLTag
forEach(java.lang.String xpath, CallBack callBack)
XMLTag
forEachChild(CallBack callBack)
Execute an action for each child in the current node.static XMLTag
from(XMLTag tag, boolean ignoreNamespaces)
static XMLTag
from(java.io.File file, boolean ignoreNamespaces)
static XMLTag
from(java.io.InputStream is, boolean ignoreNamespaces)
static XMLTag
from(java.io.Reader reader, boolean ignoreNamespaces)
static XMLTag
from(java.lang.String xmlData, boolean ignoreNamespaces)
static XMLTag
from(java.net.URL xmlLocation, boolean ignoreNamespaces)
static XMLTag
from(javax.xml.transform.Source source, boolean ignoreNamespaces)
static XMLTag
from(org.w3c.dom.Node node, boolean ignoreNamespaces)
static XMLTag
from(org.xml.sax.InputSource source, boolean ignoreNamespaces)
static XMLTag
fromCurrentTag(XMLTag tag, boolean ignoreNamespaces)
Create anotherXMLTag
instance from the hierarchy under the current tag.java.lang.String
getAttribute(java.lang.String name)
returns the attribute value of the current nodejava.lang.String
getAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments)
Returns the attribute value of the node pointed by given XPath expressionjava.lang.String[]
getAttributeNames()
java.lang.String
getCDATA()
java.lang.String
getCDATA(java.lang.String relativeXpath, java.lang.Object... arguments)
Get the CDATA of a selected nodejava.lang.String
getCDATAorText()
java.lang.String
getCDATAorText(java.lang.String relativeXpath, java.lang.Object... arguments)
Get the text of a sepcific nodeint
getChildCount()
java.util.List<org.w3c.dom.Element>
getChildElement()
java.lang.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");
java.lang.Iterable<XMLTag>
getChilds(java.lang.String relativeXpath, java.lang.Object... arguments)
Create an iterable object over selected elements.javax.xml.namespace.NamespaceContext
getContext()
org.w3c.dom.Element
getCurrentTag()
java.lang.String
getCurrentTagLocation()
java.lang.String
getCurrentTagName()
XMLTag
getInnerDocument()
java.lang.String
getInnerText()
java.lang.String
getPefix(java.lang.String namespaceURI)
Get the prefix of a namespacejava.lang.String[]
getPefixes(java.lang.String namespaceURI)
Get all bound prefixes of a namespacejava.lang.String
getText()
java.lang.String
getText(java.lang.String relativeXpath, java.lang.Object... arguments)
Get the text of a sepcific nodejava.lang.String
getTextOrCDATA()
java.lang.String
getTextOrCDATA(java.lang.String relativeXpath, java.lang.Object... arguments)
Get the text of a sepcific nodeXMLTag
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(java.lang.String nodeName)
Go to the child found with given node nameXMLTag
gotoFirstChild()
Go to the first child element of the curent node.XMLTag
gotoFirstChild(java.lang.String name)
Go to the first child occurance found having given nameXMLTag
gotoLastChild()
Go to the lastest child element of the curent node.XMLTag
gotoLastChild(java.lang.String name)
Go to the last child occurance found having given nameXMLTag
gotoParent()
Go to parent tag.XMLTag
gotoRoot()
Go to document root tagXMLTag
gotoTag(java.lang.String relativeXpath, java.lang.Object... arguments)
Go to a specific nodeboolean
hasAttribute(java.lang.String name)
Check wheter current tag contains an atributeboolean
hasAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments)
Check if targeted tag has an attribute of given nameboolean
hasTag(java.lang.String relativeXpath, java.lang.Object... arguments)
Check if a tag exist in the documentprivate boolean
isElement(org.w3c.dom.Node n)
static XMLDocBuilder
newDocument(boolean ignoreNamespaces)
java.lang.Boolean
rawXpathBoolean(java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.org.w3c.dom.Node
rawXpathNode(java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.org.w3c.dom.NodeList
rawXpathNodeSet(java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.java.lang.Number
rawXpathNumber(java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.java.lang.String
rawXpathString(java.lang.String relativeXpath, java.lang.Object... arguments)
Execute an XPath expression directly using the Java XPath API, from the current node.XMLTag
renameTo(java.lang.String newNodeName)
Replace current element name by another nameXMLTag
setAttribute(java.lang.String name, java.lang.String value)
Sets the new value on an existign attribute, and remains on the current tag.XMLTag
setAttribute(java.lang.String name, java.lang.String value, java.lang.String relativeXpath, java.lang.Object... arguments)
Sets the new value on a targetted node's attribute, and remains on the current tag.XMLTag
setAttributeIfExist(java.lang.String name, java.lang.String value)
Sets the new value on an attribute, and remains on the current tag.XMLTag
setAttributeIfExist(java.lang.String name, java.lang.String value, java.lang.String relativeXpath, java.lang.Object... arguments)
Sets the new value on a targetted node's attribute, and remains on the current tag.XMLTag
setCDATA(java.lang.String data)
Set the cdata in the current node.XMLTag
setCDATA(java.lang.String data, java.lang.String relativeXpath, java.lang.Object... arguments)
Set the cdata in the targetted node.XMLTag
setCDATAIfExist(java.lang.String data, java.lang.String relativeXpath, java.lang.Object... arguments)
Set the cdata in the targetted node.XMLTag
setText(java.lang.String text)
Set the text in the current node.XMLTag
setText(java.lang.String text, java.lang.String relativeXpath, java.lang.Object... arguments)
Set the text in the targetted node.XMLTag
setTextIfExist(java.lang.String text, java.lang.String relativeXpath, java.lang.Object... arguments)
Set the text in the targetted node.byte[]
toBytes()
byte[]
toBytes(java.lang.String encoding)
org.w3c.dom.Document
toDocument()
java.io.OutputStream
toOutputStream()
java.io.OutputStream
toOutputStream(java.lang.String encoding)
javax.xml.transform.Result
toResult()
javax.xml.transform.Result
toResult(java.lang.String encoding)
XMLTag
toResult(javax.xml.transform.Result out)
Converts this document to the result providedXMLTag
toResult(javax.xml.transform.Result out, java.lang.String encoding)
Converts this document to the result provided, overriding default encoding of xml documentjavax.xml.transform.Source
toSource()
XMLTag
toStream(java.io.OutputStream out)
Write this document to a streamXMLTag
toStream(java.io.OutputStream out, java.lang.String encoding)
Write this document to a streamXMLTag
toStream(java.io.Writer out)
Write this document to a streamXMLTag
toStream(java.io.Writer out, java.lang.String encoding)
Write this document to a streamjava.lang.String
toString()
java.lang.String
toString(java.lang.String encoding)
java.io.Writer
toWriter()
java.io.Writer
toWriter(java.lang.String encoding)
ValidationResult
validate(java.net.URL... schemaLocations)
Validate this document against specifief schemasValidationResult
validate(javax.xml.transform.Source... schemas)
Validate this document against specifief schemas
-
-
-
Field Detail
-
definition
private final XMLDocDefinition definition
-
current
org.w3c.dom.Element current
-
-
Constructor Detail
-
XMLDoc
XMLDoc(XMLDocDefinition definition)
-
-
Method Detail
-
getContext
public javax.xml.namespace.NamespaceContext getContext()
- Specified by:
getContext
in interfaceXMLTag
- Returns:
- the namespace context
-
hasAttribute
public boolean hasAttribute(java.lang.String name)
Description copied from interface:XMLTag
Check wheter current tag contains an atribute- Specified by:
hasAttribute
in interfaceXMLTag
- Parameters:
name
- Attribute name- Returns:
- true if the attribute is in current tag
-
hasAttribute
public boolean hasAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Check if targeted tag has an attribute of given name- Specified by:
hasAttribute
in interfaceXMLTag
- Parameters:
name
- the name of the attributerelativeXpath
- XPath that target the tagarguments
- optional arguments of xpath expression. Uses String.format() to build XPath expression.- Returns:
- true if the tag exist with this attribute name
-
hasTag
public boolean hasTag(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Check if a tag exist in the document
-
forEachChild
public XMLTag forEachChild(CallBack callBack)
Description copied from interface:XMLTag
Execute an action for each child in the current node.- Specified by:
forEachChild
in interfaceXMLTag
- Parameters:
callBack
- Callback method to run after the current tag of the document has changed to a child- Returns:
- this
-
forEach
public XMLTag forEach(CallBack callBack, java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an action for each selected tags from the current node.- Specified by:
forEach
in interfaceXMLTag
- Parameters:
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.- Returns:
- this
-
rawXpathString
public java.lang.String rawXpathString(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathString
in interfaceXMLTag
- Parameters:
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.STRING
return type
-
rawXpathNumber
public java.lang.Number rawXpathNumber(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNumber
in interfaceXMLTag
- Parameters:
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NUMBER
return type
-
rawXpathBoolean
public java.lang.Boolean rawXpathBoolean(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathBoolean
in interfaceXMLTag
- Parameters:
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.BOOLEAN
return type
-
rawXpathNode
public org.w3c.dom.Node rawXpathNode(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNode
in interfaceXMLTag
- Parameters:
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODE
return type
-
rawXpathNodeSet
public org.w3c.dom.NodeList rawXpathNodeSet(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Execute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNodeSet
in interfaceXMLTag
- Parameters:
relativeXpath
- The XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODESET
return type
-
getPefix
public java.lang.String getPefix(java.lang.String namespaceURI)
Description copied from interface:XMLTag
Get the prefix of a namespace
-
getPefixes
public java.lang.String[] getPefixes(java.lang.String namespaceURI)
Description copied from interface:XMLTag
Get all bound prefixes of a namespace- Specified by:
getPefixes
in interfaceXMLTag
- Parameters:
namespaceURI
- The URI of the namespace- Returns:
- a list of prefixes or an empty array.
-
addNamespace
public XMLTag addNamespace(java.lang.String prefix, java.lang.String namespaceURI)
Description copied from interface:XMLTag
Add a namespace to the document- Specified by:
addNamespace
in interfaceXMLTag
- Parameters:
prefix
- The prefix of the namespacenamespaceURI
- The URI of the namespace- Returns:
- this
-
addDocument
public XMLTag addDocument(XMLTag tag)
Description copied from interface:XMLTag
Inserts anotherXMLTag
instance under the current tag. The whole document will be inserted.- Specified by:
addDocument
in interfaceXMLTag
- Parameters:
tag
- TheXMLTag
instance to insert- Returns:
- this
-
addDocument
public XMLTag addDocument(org.w3c.dom.Document doc)
Description copied from interface:XMLTag
Inserts anotherDocument
instance under the current tag- Specified by:
addDocument
in interfaceXMLTag
- Parameters:
doc
- TheDocument
instance to insert- Returns:
- this
-
addTag
public XMLTag addTag(XMLTag tag)
Description copied from interface:XMLTag
Inserts anotherXMLTag
tag hierarchy under the current tag. Only the current tag of the given document will be inserted with its hierarchy, not the whole document.
-
addTag
public XMLTag addTag(org.w3c.dom.Element tag)
Description copied from interface:XMLTag
Inserts aElement
instance and its hierarchy under the current tag
-
addTag
public XMLTag addTag(java.lang.String name)
Description copied from interface:XMLTag
Create a tag under the current location and use it as the current node
-
addAttribute
public XMLTag addAttribute(java.lang.String name, java.lang.String value)
Description copied from interface:XMLTag
Create a new attribute for the current node- Specified by:
addAttribute
in interfaceXMLTag
- Parameters:
name
- Name of the attribute to addvalue
- value of the attribute to add- Returns:
- this
-
addAttribute
public XMLTag addAttribute(org.w3c.dom.Attr attr)
Description copied from interface:XMLTag
Add given attribute to current element- Specified by:
addAttribute
in interfaceXMLTag
- Parameters:
attr
- The attribute to insert- Returns:
- this
-
addText
public XMLTag addText(java.lang.String text)
Description copied from interface:XMLTag
Add a text node under the current node, and jump to the parent node. This enables the create or quick documents like this:addTag("name").addText("Bob")addTag("sex").addText("M")addTag("age").addText("30")
<name>Bob</name><sex>M</sex><age>30</age>
-
addText
public XMLTag addText(org.w3c.dom.Text text)
Description copied from interface:XMLTag
Add a text note to the current tag
-
addCDATA
public XMLTag addCDATA(java.lang.String data)
Description copied from interface:XMLTag
Add a data node under the current node, and jump to the parent node. This enables the create or quick documents like this:addTag("name").addCDATA("Bob")addTag("sex").addCDATA("M")addTag("age").addCDATA("30")
<name><![CDATA[Bob]]></name><sex><![CDATA[M]]></sex><age><![CDATA[30]]></age>
-
addCDATA
public XMLTag addCDATA(org.w3c.dom.CDATASection data)
Description copied from interface:XMLTag
Add a CDATA note to the current tag
-
delete
public XMLTag delete()
Description copied from interface:XMLTag
Delete current tag and its childs. If the current tag is the root tag of xml document, it cannot be delete. It can just be replaced. In this case, an exception is thrown
-
deleteChilds
public XMLTag deleteChilds()
Description copied from interface:XMLTag
Delete all existing elements of this node- Specified by:
deleteChilds
in interfaceXMLTag
- Returns:
- this
-
deleteAttributes
public XMLTag deleteAttributes()
Description copied from interface:XMLTag
Delete all existing attributes of current node- Specified by:
deleteAttributes
in interfaceXMLTag
- Returns:
- this
-
deleteAttribute
public XMLTag deleteAttribute(java.lang.String name)
Description copied from interface:XMLTag
Delete an attribute of the current node.- Specified by:
deleteAttribute
in interfaceXMLTag
- Parameters:
name
- attribute name- Returns:
- this
-
deleteAttributeIfExists
public XMLTag deleteAttributeIfExists(java.lang.String name)
Description copied from interface:XMLTag
Delete an attribute of the current node, if it exists- Specified by:
deleteAttributeIfExists
in interfaceXMLTag
- Parameters:
name
- attribute name- Returns:
- this
-
renameTo
public XMLTag renameTo(java.lang.String newNodeName)
Description copied from interface:XMLTag
Replace current element name by another name
-
deletePrefixes
public XMLTag deletePrefixes()
Description copied from interface:XMLTag
Remove any prefix and namespaces contained in the tag name, childs and attributes, thus changing namespace and tag name. This can be very useful if you are working in a document when you want to ignore namespaces, if you don't know the tag prefix- Specified by:
deletePrefixes
in interfaceXMLTag
- Returns:
- this
-
getInnerDocument
public XMLTag getInnerDocument()
- Specified by:
getInnerDocument
in interfaceXMLTag
- Returns:
- Another XMLTag instance in which the current tag becomes de root element of the new document, and it contains all inner elements as in the previous document.
-
getInnerText
public java.lang.String getInnerText()
- Specified by:
getInnerText
in interfaceXMLTag
- Returns:
- The text representation of the inner nodes of the current node. The current node is outputed as the root element of inner tags.
-
gotoParent
public XMLTag gotoParent()
Description copied from interface:XMLTag
Go to parent tag. Do nothing if we are already at root- Specified by:
gotoParent
in interfaceXMLTag
- Returns:
- this
-
gotoChild
public XMLTag gotoChild()
Description copied from interface:XMLTag
Go to the only child element of the curent node.
-
gotoChild
public XMLTag gotoChild(int i)
Description copied from interface:XMLTag
Go to the Nth child of the curent node.
-
gotoChild
public XMLTag gotoChild(java.lang.String nodeName)
Description copied from interface:XMLTag
Go to the child found with given node name
-
gotoFirstChild
public XMLTag gotoFirstChild() throws XMLDocumentException
Description copied from interface:XMLTag
Go to the first child element of the curent node.- Specified by:
gotoFirstChild
in interfaceXMLTag
- Returns:
- this
- Throws:
XMLDocumentException
- If the current node has no child at all
-
gotoFirstChild
public XMLTag gotoFirstChild(java.lang.String name) throws XMLDocumentException
Description copied from interface:XMLTag
Go to the first child occurance found having given name- Specified by:
gotoFirstChild
in interfaceXMLTag
- Parameters:
name
- Name of the child to go at- Returns:
- this
- Throws:
XMLDocumentException
- If the current node has no child at all
-
gotoLastChild
public XMLTag gotoLastChild() throws XMLDocumentException
Description copied from interface:XMLTag
Go to the lastest child element of the curent node.- Specified by:
gotoLastChild
in interfaceXMLTag
- Returns:
- this
- Throws:
XMLDocumentException
- If the current node has no child at all
-
gotoLastChild
public XMLTag gotoLastChild(java.lang.String name) throws XMLDocumentException
Description copied from interface:XMLTag
Go to the last child occurance found having given name- Specified by:
gotoLastChild
in interfaceXMLTag
- Parameters:
name
- Name of the child to go at- Returns:
- this
- Throws:
XMLDocumentException
- If the current node has no child at all
-
gotoTag
public XMLTag gotoTag(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Go to a specific node
-
getCurrentTag
public org.w3c.dom.Element getCurrentTag()
- Specified by:
getCurrentTag
in interfaceXMLTag
- Returns:
- the current tag
-
getChildCount
public int getChildCount()
- Specified by:
getChildCount
in interfaceXMLTag
- Returns:
- The number of child for the current tag
-
getChilds
public java.lang.Iterable<XMLTag> getChilds()
Description copied from interface: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");
-
getChilds
public java.lang.Iterable<XMLTag> getChilds(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Create an iterable object over selected elements. Act as the getChilds method: The current position of XMLTag is modified at each iteration. Thus, if you break in the iteration, the current position will not be the same as the position before.
-
getChildElement
public java.util.List<org.w3c.dom.Element> getChildElement()
- Specified by:
getChildElement
in interfaceXMLTag
- Returns:
- The child element's list
-
getCurrentTagName
public java.lang.String getCurrentTagName()
- Specified by:
getCurrentTagName
in interfaceXMLTag
- Returns:
- the current tag name
-
getCurrentTagLocation
public java.lang.String getCurrentTagLocation()
- Specified by:
getCurrentTagLocation
in interfaceXMLTag
- Returns:
- An XPath expression representing the current tag location in the document. If you are in the root node and run gotoTag() giving this XPath expression, you will return to the current node.
-
getAttribute
public java.lang.String getAttribute(java.lang.String name)
Description copied from interface:XMLTag
returns the attribute value of the current node- Specified by:
getAttribute
in interfaceXMLTag
- Parameters:
name
- attribute name- Returns:
- attribute value
-
findAttribute
public java.lang.String findAttribute(java.lang.String name)
Description copied from interface:XMLTag
returns the attribute value of the current node or null if the attribute does not exist- Specified by:
findAttribute
in interfaceXMLTag
- Parameters:
name
- attribute name- Returns:
- attribute value or null if no attribute
-
getAttribute
public java.lang.String getAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Returns the attribute value of the node pointed by given XPath expression- Specified by:
getAttribute
in interfaceXMLTag
- Parameters:
name
- attribute namerelativeXpath
- XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- attribute value
-
findAttribute
public java.lang.String findAttribute(java.lang.String name, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Returns the attribute value of the node pointed by given XPath expression or null if the attribute does not exist- Specified by:
findAttribute
in interfaceXMLTag
- Parameters:
name
- attribute namerelativeXpath
- XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- the attribute value or null if the attribute does not exist
- Throws:
XMLDocumentException
- targetted node does not exist or XPath expression is invalid
-
getAttributeNames
public java.lang.String[] getAttributeNames()
- Specified by:
getAttributeNames
in interfaceXMLTag
- Returns:
- all attribute names of current node
-
getText
public java.lang.String getText(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Get the text of a sepcific node
-
getText
public java.lang.String getText()
-
getTextOrCDATA
public java.lang.String getTextOrCDATA()
- Specified by:
getTextOrCDATA
in interfaceXMLTag
- Returns:
- The text content of the current node, if none tries to get the CDATA content, if none returns ""
-
getTextOrCDATA
public java.lang.String getTextOrCDATA(java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Get the text of a sepcific node- Specified by:
getTextOrCDATA
in interfaceXMLTag
- Parameters:
relativeXpath
- XPath expression that select the nodearguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The text content of the current node, if none tries to get the CDATA content, if none returns ""
- Throws:
XMLDocumentException
- If the XPath expression is not valid or if the node does not exist
-
getCDATAorText
public java.lang.String getCDATAorText()
- Specified by:
getCDATAorText
in interfaceXMLTag
- Returns:
- The CDATA content of the current node, if none tries to get the text content, if none returns ""
-
getCDATAorText
public java.lang.String getCDATAorText(java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Get the text of a sepcific node- Specified by:
getCDATAorText
in interfaceXMLTag
- Parameters:
relativeXpath
- XPath expression that select the nodearguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The CDATA content of the current node, if none tries to get the text content, if none returns ""
- Throws:
XMLDocumentException
- If the XPath expression is not valid or if the node does not exist
-
getCDATA
public java.lang.String getCDATA(java.lang.String relativeXpath, java.lang.Object... arguments)
Description copied from interface:XMLTag
Get the CDATA of a selected node
-
getCDATA
public java.lang.String getCDATA()
-
toDocument
public org.w3c.dom.Document toDocument()
- Specified by:
toDocument
in interfaceXMLTag
- Returns:
- the Document
-
toSource
public javax.xml.transform.Source toSource()
-
toString
public java.lang.String toString()
-
toString
public java.lang.String toString(java.lang.String encoding)
-
toBytes
public byte[] toBytes()
-
toBytes
public byte[] toBytes(java.lang.String encoding)
-
toStream
public XMLTag toStream(java.io.OutputStream out)
Description copied from interface:XMLTag
Write this document to a stream
-
toStream
public XMLTag toStream(java.io.OutputStream out, java.lang.String encoding)
Description copied from interface:XMLTag
Write this document to a stream
-
toStream
public XMLTag toStream(java.io.Writer out)
Description copied from interface:XMLTag
Write this document to a stream
-
toStream
public XMLTag toStream(java.io.Writer out, java.lang.String encoding)
Description copied from interface:XMLTag
Write this document to a stream
-
toResult
public javax.xml.transform.Result toResult()
-
toResult
public javax.xml.transform.Result toResult(java.lang.String encoding)
-
toOutputStream
public java.io.OutputStream toOutputStream()
- Specified by:
toOutputStream
in interfaceXMLTag
- Returns:
- A stream where the document has already been written into
-
toOutputStream
public java.io.OutputStream toOutputStream(java.lang.String encoding)
- Specified by:
toOutputStream
in interfaceXMLTag
- Parameters:
encoding
- The new encoding- Returns:
- A stream where the document has already been written into
-
toWriter
public java.io.Writer toWriter()
-
toWriter
public java.io.Writer toWriter(java.lang.String encoding)
-
toResult
public XMLTag toResult(javax.xml.transform.Result out)
Description copied from interface:XMLTag
Converts this document to the result provided
-
toResult
public XMLTag toResult(javax.xml.transform.Result out, java.lang.String encoding)
Description copied from interface:XMLTag
Converts this document to the result provided, overriding default encoding of xml document
-
validate
public ValidationResult validate(javax.xml.transform.Source... schemas)
Description copied from interface:XMLTag
Validate this document against specifief schemas
-
validate
public ValidationResult validate(java.net.URL... schemaLocations)
Description copied from interface:XMLTag
Validate this document against specifief schemas
-
isElement
private boolean isElement(org.w3c.dom.Node n)
-
childs
private java.util.List<org.w3c.dom.Element> childs(org.w3c.dom.Element e)
-
attr
private java.util.List<org.w3c.dom.Attr> attr(org.w3c.dom.Element e)
-
childs
private java.util.List<org.w3c.dom.Node> childs(short type)
-
duplicate
public XMLTag duplicate()
-
setText
public XMLTag setText(java.lang.String text)
Description copied from interface:XMLTag
Set the text in the current node. This method will replace all existing text and cdata by the given text. Also Jump after to the parent node. This enables the quicly replace test on several nodes like this:gotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")
<name>Bob</name><sex>M</sex><age>30</age>
-
setText
public XMLTag setText(java.lang.String text, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Set the text in the targetted node. This method will replace all existing text and cdata by the given text, but remains on the current tag.- Specified by:
setText
in interfaceXMLTag
- Parameters:
text
- text to put under this noderelativeXpath
- XPath expression that select the nodearguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- this
- Throws:
XMLDocumentException
- If the XPath expression is invalid or if the node does not exist
-
setTextIfExist
public XMLTag setTextIfExist(java.lang.String text, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Set the text in the targetted node. This method will replace all existing text and cdata by the given text, but remains on the current tag. If the targetted node does not exist, do nothing.- Specified by:
setTextIfExist
in interfaceXMLTag
- Parameters:
text
- text to put under this noderelativeXpath
- XPath expression that select the nodearguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- this
- Throws:
XMLDocumentException
- If the XPath expression is invalid
-
setCDATA
public XMLTag setCDATA(java.lang.String data)
Description copied from interface:XMLTag
Set the cdata in the current node. This method will replace all existing text and cdata by the given cdata Also Jump after to the parent node. This enables the quicly replace test on several nodes like this:gotoChild("name").setText("Bob").gotoChild("sex").setText("M").gotoChild("age").setText("30")
<name>Bob</name><sex>M</sex><age>30</age>
-
setCDATA
public XMLTag setCDATA(java.lang.String data, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Set the cdata in the targetted node. This method will replace all existing text and cdata by the given cdata, but remains on the current tag.- Specified by:
setCDATA
in interfaceXMLTag
- Parameters:
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.- Returns:
- this
- Throws:
XMLDocumentException
- If the XPath expression is invalid or if the node does not exist
-
setCDATAIfExist
public XMLTag setCDATAIfExist(java.lang.String data, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Set the cdata in the targetted node. This method will replace all existing text and cdata by the given cdata, but remains on the current tag. If the targetted node does not exist, do nothing.- Specified by:
setCDATAIfExist
in interfaceXMLTag
- Parameters:
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.- Returns:
- this
- Throws:
XMLDocumentException
- If the XPath expression is invalid
-
setAttribute
public XMLTag setAttribute(java.lang.String name, java.lang.String value) throws XMLDocumentException
Description copied from interface:XMLTag
Sets the new value on an existign attribute, and remains on the current tag.- Specified by:
setAttribute
in interfaceXMLTag
- Parameters:
name
- attribute namevalue
- new attribute'svalue- Returns:
- attribute value
- Throws:
XMLDocumentException
- If the attribute does not exist
-
setAttributeIfExist
public XMLTag setAttributeIfExist(java.lang.String name, java.lang.String value)
Description copied from interface:XMLTag
Sets the new value on an attribute, and remains on the current tag. If it does not exist, do nothing.- Specified by:
setAttributeIfExist
in interfaceXMLTag
- Parameters:
name
- attribute namevalue
- new attribute value- Returns:
- attribute value
-
setAttribute
public XMLTag setAttribute(java.lang.String name, java.lang.String value, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Sets the new value on a targetted node's attribute, and remains on the current tag.- Specified by:
setAttribute
in interfaceXMLTag
- Parameters:
name
- attribute namevalue
- new attribute's valuerelativeXpath
- XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- attribute value
- Throws:
XMLDocumentException
- Attribute does not exist, targetted node does not exit, or XPath expression is invalid
-
setAttributeIfExist
public XMLTag setAttributeIfExist(java.lang.String name, java.lang.String value, java.lang.String relativeXpath, java.lang.Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTag
Sets the new value on a targetted node's attribute, and remains on the current tag. If the attribute does not exist, do nothing.- Specified by:
setAttributeIfExist
in interfaceXMLTag
- Parameters:
name
- attribute namevalue
- new attribute's valuerelativeXpath
- XPath expressionarguments
- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- attribute value
- Throws:
XMLDocumentException
- XPath expression is invalid or targetted node does not exist
-
newDocument
public static XMLDocBuilder newDocument(boolean ignoreNamespaces)
-
from
public static XMLTag from(org.w3c.dom.Node node, boolean ignoreNamespaces)
-
from
public static XMLTag from(org.xml.sax.InputSource source, boolean ignoreNamespaces)
-
from
public static XMLTag from(java.io.Reader reader, boolean ignoreNamespaces)
-
from
public static XMLTag from(java.io.InputStream is, boolean ignoreNamespaces)
-
from
public static XMLTag from(java.io.File file, boolean ignoreNamespaces)
-
from
public static XMLTag from(java.net.URL xmlLocation, boolean ignoreNamespaces)
-
from
public static XMLTag from(java.lang.String xmlData, boolean ignoreNamespaces)
-
from
public static XMLTag from(javax.xml.transform.Source source, boolean ignoreNamespaces)
-
fromCurrentTag
public static XMLTag fromCurrentTag(XMLTag tag, boolean ignoreNamespaces)
Create anotherXMLTag
instance from the hierarchy under the current tag. The current tag becomes the root tag.- Parameters:
tag
- The current XML Tag positionned to the new root tagignoreNamespaces
- Wheter to build a namespace aware document- Returns:
- The inner XMLTag instance
-
-