Package com.mycila.xmltool
Class XMLDoc
- java.lang.Object
-
- com.mycila.xmltool.XMLDoc
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description XMLTagaddAttribute(String name, String value)Create a new attribute for the current nodeXMLTagaddAttribute(Attr attr)Add given attribute to current elementXMLTagaddCDATA(String data)Add a data node under the current node, and jump to the parent node.XMLTagaddCDATA(CDATASection data)Add a CDATA note to the current tagXMLTagaddDocument(XMLTag tag)Inserts anotherXMLTaginstance under the current tag.XMLTagaddDocument(Document doc)Inserts anotherDocumentinstance under the current tagXMLTagaddNamespace(String prefix, String namespaceURI)Add a namespace to the documentXMLTagaddTag(XMLTag tag)Inserts anotherXMLTagtag hierarchy under the current tag.XMLTagaddTag(String name)Create a tag under the current location and use it as the current nodeXMLTagaddTag(Element tag)Inserts aElementinstance and its hierarchy under the current tagXMLTagaddText(String text)Add a text node under the current node, and jump to the parent node.XMLTagaddText(Text text)Add a text note to the current tagXMLTagdelete()Delete current tag and its childs.XMLTagdeleteAttribute(String name)Delete an attribute of the current node.XMLTagdeleteAttributeIfExists(String name)Delete an attribute of the current node, if it existsXMLTagdeleteAttributes()Delete all existing attributes of current nodeXMLTagdeleteChilds()Delete all existing elements of this nodeXMLTagdeletePrefixes()Remove any prefix and namespaces contained in the tag name, childs and attributes, thus changing namespace and tag name.XMLTagduplicate()StringfindAttribute(String name)returns the attribute value of the current node or null if the attribute does not existStringfindAttribute(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 existXMLTagforEach(CallBack callBack, String relativeXpath, Object... arguments)Execute an action for each selected tags from the current node.XMLTagforEach(String xpath, CallBack callBack)XMLTagforEachChild(CallBack callBack)Execute an action for each child in the current node.static XMLTagfrom(XMLTag tag, boolean ignoreNamespaces)static XMLTagfrom(File file, boolean ignoreNamespaces)static XMLTagfrom(InputStream is, boolean ignoreNamespaces)static XMLTagfrom(Reader reader, boolean ignoreNamespaces)static XMLTagfrom(String xmlData, boolean ignoreNamespaces)static XMLTagfrom(URL xmlLocation, boolean ignoreNamespaces)static XMLTagfrom(Source source, boolean ignoreNamespaces)static XMLTagfrom(Node node, boolean ignoreNamespaces)static XMLTagfrom(InputSource source, boolean ignoreNamespaces)static XMLTagfromCurrentTag(XMLTag tag, boolean ignoreNamespaces)Create anotherXMLTaginstance from the hierarchy under the current tag.StringgetAttribute(String name)returns the attribute value of the current nodeStringgetAttribute(String name, String relativeXpath, Object... arguments)Returns the attribute value of the node pointed by given XPath expressionString[]getAttributeNames()StringgetCDATA()StringgetCDATA(String relativeXpath, Object... arguments)Get the CDATA of a selected nodeStringgetCDATAorText()StringgetCDATAorText(String relativeXpath, Object... arguments)Get the text of a sepcific nodeintgetChildCount()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.NamespaceContextgetContext()ElementgetCurrentTag()StringgetCurrentTagLocation()StringgetCurrentTagName()XMLTaggetInnerDocument()StringgetInnerText()StringgetPefix(String namespaceURI)Get the prefix of a namespaceString[]getPefixes(String namespaceURI)Get all bound prefixes of a namespaceStringgetText()StringgetText(String relativeXpath, Object... arguments)Get the text of a sepcific nodeStringgetTextOrCDATA()StringgetTextOrCDATA(String relativeXpath, Object... arguments)Get the text of a sepcific nodeXMLTaggotoChild()Go to the only child element of the curent node.XMLTaggotoChild(int i)Go to the Nth child of the curent node.XMLTaggotoChild(String nodeName)Go to the child found with given node nameXMLTaggotoFirstChild()Go to the first child element of the curent node.XMLTaggotoFirstChild(String name)Go to the first child occurance found having given nameXMLTaggotoLastChild()Go to the lastest child element of the curent node.XMLTaggotoLastChild(String name)Go to the last child occurance found having given nameXMLTaggotoParent()Go to parent tag.XMLTaggotoRoot()Go to document root tagXMLTaggotoTag(String relativeXpath, Object... arguments)Go to a specific nodebooleanhasAttribute(String name)Check wheter current tag contains an atributebooleanhasAttribute(String name, String relativeXpath, Object... arguments)Check if targeted tag has an attribute of given namebooleanhasTag(String relativeXpath, Object... arguments)Check if a tag exist in the documentstatic XMLDocBuildernewDocument(boolean ignoreNamespaces)BooleanrawXpathBoolean(String relativeXpath, Object... arguments)Execute an XPath expression directly using the Java XPath API, from the current node.NoderawXpathNode(String relativeXpath, Object... arguments)Execute an XPath expression directly using the Java XPath API, from the current node.NodeListrawXpathNodeSet(String relativeXpath, Object... arguments)Execute an XPath expression directly using the Java XPath API, from the current node.NumberrawXpathNumber(String relativeXpath, Object... arguments)Execute an XPath expression directly using the Java XPath API, from the current node.StringrawXpathString(String relativeXpath, Object... arguments)Execute an XPath expression directly using the Java XPath API, from the current node.XMLTagrenameTo(String newNodeName)Replace current element name by another nameXMLTagsetAttribute(String name, String value)Sets the new value on an existign attribute, and remains on the current tag.XMLTagsetAttribute(String name, String value, String relativeXpath, Object... arguments)Sets the new value on a targetted node's attribute, and remains on the current tag.XMLTagsetAttributeIfExist(String name, String value)Sets the new value on an attribute, and remains on the current tag.XMLTagsetAttributeIfExist(String name, String value, String relativeXpath, Object... arguments)Sets the new value on a targetted node's attribute, and remains on the current tag.XMLTagsetCDATA(String data)Set the cdata in the current node.XMLTagsetCDATA(String data, String relativeXpath, Object... arguments)Set the cdata in the targetted node.XMLTagsetCDATAIfExist(String data, String relativeXpath, Object... arguments)Set the cdata in the targetted node.XMLTagsetText(String text)Set the text in the current node.XMLTagsetText(String text, String relativeXpath, Object... arguments)Set the text in the targetted node.XMLTagsetTextIfExist(String text, String relativeXpath, Object... arguments)Set the text in the targetted node.byte[]toBytes()byte[]toBytes(String encoding)DocumenttoDocument()OutputStreamtoOutputStream()OutputStreamtoOutputStream(String encoding)ResulttoResult()ResulttoResult(String encoding)XMLTagtoResult(Result out)Converts this document to the result providedXMLTagtoResult(Result out, String encoding)Converts this document to the result provided, overriding default encoding of xml documentSourcetoSource()XMLTagtoStream(OutputStream out)Write this document to a streamXMLTagtoStream(OutputStream out, String encoding)Write this document to a streamXMLTagtoStream(Writer out)Write this document to a streamXMLTagtoStream(Writer out, String encoding)Write this document to a streamStringtoString()StringtoString(String encoding)WritertoWriter()WritertoWriter(String encoding)ValidationResultvalidate(URL... schemaLocations)Validate this document against specifief schemasValidationResultvalidate(Source... schemas)Validate this document against specifief schemas
-
-
-
Method Detail
-
getContext
public NamespaceContext getContext()
- Specified by:
getContextin interfaceXMLTag- Returns:
- the namespace context
-
hasAttribute
public boolean hasAttribute(String name)
Description copied from interface:XMLTagCheck wheter current tag contains an atribute- Specified by:
hasAttributein interfaceXMLTag- Parameters:
name- Attribute name- Returns:
- true if the attribute is in current tag
-
hasAttribute
public boolean hasAttribute(String name, String relativeXpath, Object... arguments)
Description copied from interface:XMLTagCheck if targeted tag has an attribute of given name- Specified by:
hasAttributein 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(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagCheck if a tag exist in the document
-
forEachChild
public XMLTag forEachChild(CallBack callBack)
Description copied from interface:XMLTagExecute an action for each child in the current node.- Specified by:
forEachChildin 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, String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an action for each selected tags from the current node.- Specified by:
forEachin 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 String rawXpathString(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathStringin interfaceXMLTag- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.STRINGreturn type
-
rawXpathNumber
public Number rawXpathNumber(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNumberin interfaceXMLTag- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NUMBERreturn type
-
rawXpathBoolean
public Boolean rawXpathBoolean(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathBooleanin interfaceXMLTag- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.BOOLEANreturn type
-
rawXpathNode
public Node rawXpathNode(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNodein interfaceXMLTag- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODEreturn type
-
rawXpathNodeSet
public NodeList rawXpathNodeSet(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagExecute an XPath expression directly using the Java XPath API, from the current node.- Specified by:
rawXpathNodeSetin interfaceXMLTag- Parameters:
relativeXpath- The XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- The
XPathConstants.NODESETreturn type
-
getPefix
public String getPefix(String namespaceURI)
Description copied from interface:XMLTagGet the prefix of a namespace
-
getPefixes
public String[] getPefixes(String namespaceURI)
Description copied from interface:XMLTagGet all bound prefixes of a namespace- Specified by:
getPefixesin interfaceXMLTag- Parameters:
namespaceURI- The URI of the namespace- Returns:
- a list of prefixes or an empty array.
-
addNamespace
public XMLTag addNamespace(String prefix, String namespaceURI)
Description copied from interface:XMLTagAdd a namespace to the document- Specified by:
addNamespacein 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:XMLTagInserts anotherXMLTaginstance under the current tag. The whole document will be inserted.- Specified by:
addDocumentin interfaceXMLTag- Parameters:
tag- TheXMLTaginstance to insert- Returns:
- this
-
addDocument
public XMLTag addDocument(Document doc)
Description copied from interface:XMLTagInserts anotherDocumentinstance under the current tag- Specified by:
addDocumentin interfaceXMLTag- Parameters:
doc- TheDocumentinstance to insert- Returns:
- this
-
addTag
public XMLTag addTag(XMLTag tag)
Description copied from interface:XMLTagInserts anotherXMLTagtag 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(Element tag)
Description copied from interface:XMLTagInserts aElementinstance and its hierarchy under the current tag
-
addTag
public XMLTag addTag(String name)
Description copied from interface:XMLTagCreate a tag under the current location and use it as the current node
-
addAttribute
public XMLTag addAttribute(String name, String value)
Description copied from interface:XMLTagCreate a new attribute for the current node- Specified by:
addAttributein interfaceXMLTag- Parameters:
name- Name of the attribute to addvalue- value of the attribute to add- Returns:
- this
-
addAttribute
public XMLTag addAttribute(Attr attr)
Description copied from interface:XMLTagAdd given attribute to current element- Specified by:
addAttributein interfaceXMLTag- Parameters:
attr- The attribute to insert- Returns:
- this
-
addText
public XMLTag addText(String text)
Description copied from interface:XMLTagAdd 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(Text text)
Description copied from interface:XMLTagAdd a text note to the current tag
-
addCDATA
public XMLTag addCDATA(String data)
Description copied from interface:XMLTagAdd 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(CDATASection data)
Description copied from interface:XMLTagAdd a CDATA note to the current tag
-
delete
public XMLTag delete()
Description copied from interface:XMLTagDelete 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:XMLTagDelete all existing elements of this node- Specified by:
deleteChildsin interfaceXMLTag- Returns:
- this
-
deleteAttributes
public XMLTag deleteAttributes()
Description copied from interface:XMLTagDelete all existing attributes of current node- Specified by:
deleteAttributesin interfaceXMLTag- Returns:
- this
-
deleteAttribute
public XMLTag deleteAttribute(String name)
Description copied from interface:XMLTagDelete an attribute of the current node.- Specified by:
deleteAttributein interfaceXMLTag- Parameters:
name- attribute name- Returns:
- this
-
deleteAttributeIfExists
public XMLTag deleteAttributeIfExists(String name)
Description copied from interface:XMLTagDelete an attribute of the current node, if it exists- Specified by:
deleteAttributeIfExistsin interfaceXMLTag- Parameters:
name- attribute name- Returns:
- this
-
renameTo
public XMLTag renameTo(String newNodeName)
Description copied from interface:XMLTagReplace current element name by another name
-
deletePrefixes
public XMLTag deletePrefixes()
Description copied from interface:XMLTagRemove 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:
deletePrefixesin interfaceXMLTag- Returns:
- this
-
getInnerDocument
public XMLTag getInnerDocument()
- Specified by:
getInnerDocumentin 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 String getInnerText()
- Specified by:
getInnerTextin 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:XMLTagGo to parent tag. Do nothing if we are already at root- Specified by:
gotoParentin interfaceXMLTag- Returns:
- this
-
gotoChild
public XMLTag gotoChild()
Description copied from interface:XMLTagGo to the only child element of the curent node.
-
gotoChild
public XMLTag gotoChild(int i)
Description copied from interface:XMLTagGo to the Nth child of the curent node.
-
gotoChild
public XMLTag gotoChild(String nodeName)
Description copied from interface:XMLTagGo to the child found with given node name
-
gotoFirstChild
public XMLTag gotoFirstChild() throws XMLDocumentException
Description copied from interface:XMLTagGo to the first child element of the curent node.- Specified by:
gotoFirstChildin interfaceXMLTag- Returns:
- this
- Throws:
XMLDocumentException- If the current node has no child at all
-
gotoFirstChild
public XMLTag gotoFirstChild(String name) throws XMLDocumentException
Description copied from interface:XMLTagGo to the first child occurance found having given name- Specified by:
gotoFirstChildin 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:XMLTagGo to the lastest child element of the curent node.- Specified by:
gotoLastChildin interfaceXMLTag- Returns:
- this
- Throws:
XMLDocumentException- If the current node has no child at all
-
gotoLastChild
public XMLTag gotoLastChild(String name) throws XMLDocumentException
Description copied from interface:XMLTagGo to the last child occurance found having given name- Specified by:
gotoLastChildin 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(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagGo to a specific node
-
getCurrentTag
public Element getCurrentTag()
- Specified by:
getCurrentTagin interfaceXMLTag- Returns:
- the current tag
-
getChildCount
public int getChildCount()
- Specified by:
getChildCountin interfaceXMLTag- Returns:
- The number of child for the current tag
-
getChilds
public Iterable<XMLTag> getChilds()
Description copied from interface:XMLTagXMLTag 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 Iterable<XMLTag> getChilds(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagCreate 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 List<Element> getChildElement()
- Specified by:
getChildElementin interfaceXMLTag- Returns:
- The child element's list
-
getCurrentTagName
public String getCurrentTagName()
- Specified by:
getCurrentTagNamein interfaceXMLTag- Returns:
- the current tag name
-
getCurrentTagLocation
public String getCurrentTagLocation()
- Specified by:
getCurrentTagLocationin 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 String getAttribute(String name)
Description copied from interface:XMLTagreturns the attribute value of the current node- Specified by:
getAttributein interfaceXMLTag- Parameters:
name- attribute name- Returns:
- attribute value
-
findAttribute
public String findAttribute(String name)
Description copied from interface:XMLTagreturns the attribute value of the current node or null if the attribute does not exist- Specified by:
findAttributein interfaceXMLTag- Parameters:
name- attribute name- Returns:
- attribute value or null if no attribute
-
getAttribute
public String getAttribute(String name, String relativeXpath, Object... arguments)
Description copied from interface:XMLTagReturns the attribute value of the node pointed by given XPath expression- Specified by:
getAttributein interfaceXMLTag- Parameters:
name- attribute namerelativeXpath- XPath expressionarguments- facultative Xpath expression arguments. Uses String.format() to build XPath expression.- Returns:
- attribute value
-
findAttribute
public String findAttribute(String name, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagReturns the attribute value of the node pointed by given XPath expression or null if the attribute does not exist- Specified by:
findAttributein 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 String[] getAttributeNames()
- Specified by:
getAttributeNamesin interfaceXMLTag- Returns:
- all attribute names of current node
-
getText
public String getText(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagGet the text of a sepcific node
-
getText
public String getText()
-
getTextOrCDATA
public String getTextOrCDATA()
- Specified by:
getTextOrCDATAin interfaceXMLTag- Returns:
- The text content of the current node, if none tries to get the CDATA content, if none returns ""
-
getTextOrCDATA
public String getTextOrCDATA(String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagGet the text of a sepcific node- Specified by:
getTextOrCDATAin 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 String getCDATAorText()
- Specified by:
getCDATAorTextin interfaceXMLTag- Returns:
- The CDATA content of the current node, if none tries to get the text content, if none returns ""
-
getCDATAorText
public String getCDATAorText(String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagGet the text of a sepcific node- Specified by:
getCDATAorTextin 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 String getCDATA(String relativeXpath, Object... arguments)
Description copied from interface:XMLTagGet the CDATA of a selected node
-
getCDATA
public String getCDATA()
-
toDocument
public Document toDocument()
- Specified by:
toDocumentin interfaceXMLTag- Returns:
- the Document
-
toSource
public Source toSource()
-
toString
public String toString()
-
toBytes
public byte[] toBytes()
-
toBytes
public byte[] toBytes(String encoding)
-
toStream
public XMLTag toStream(OutputStream out)
Description copied from interface:XMLTagWrite this document to a stream
-
toStream
public XMLTag toStream(OutputStream out, String encoding)
Description copied from interface:XMLTagWrite this document to a stream
-
toStream
public XMLTag toStream(Writer out)
Description copied from interface:XMLTagWrite this document to a stream
-
toStream
public XMLTag toStream(Writer out, String encoding)
Description copied from interface:XMLTagWrite this document to a stream
-
toResult
public Result toResult()
-
toOutputStream
public OutputStream toOutputStream()
- Specified by:
toOutputStreamin interfaceXMLTag- Returns:
- A stream where the document has already been written into
-
toOutputStream
public OutputStream toOutputStream(String encoding)
- Specified by:
toOutputStreamin interfaceXMLTag- Parameters:
encoding- The new encoding- Returns:
- A stream where the document has already been written into
-
toWriter
public Writer toWriter()
-
toResult
public XMLTag toResult(Result out)
Description copied from interface:XMLTagConverts this document to the result provided
-
toResult
public XMLTag toResult(Result out, String encoding)
Description copied from interface:XMLTagConverts this document to the result provided, overriding default encoding of xml document
-
validate
public ValidationResult validate(Source... schemas)
Description copied from interface:XMLTagValidate this document against specifief schemas
-
validate
public ValidationResult validate(URL... schemaLocations)
Description copied from interface:XMLTagValidate this document against specifief schemas
-
duplicate
public XMLTag duplicate()
-
setText
public XMLTag setText(String text)
Description copied from interface:XMLTagSet 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(String text, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSet 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:
setTextin 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(String text, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSet 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:
setTextIfExistin 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(String data)
Description copied from interface:XMLTagSet 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(String data, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSet 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:
setCDATAin 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(String data, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSet 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:
setCDATAIfExistin 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(String name, String value) throws XMLDocumentException
Description copied from interface:XMLTagSets the new value on an existign attribute, and remains on the current tag.- Specified by:
setAttributein interfaceXMLTag- Parameters:
name- attribute namevalue- new attribute'svalue- Returns:
- attribute value
- Throws:
XMLDocumentException- If the attribute does not exist
-
setAttributeIfExist
public XMLTag setAttributeIfExist(String name, String value)
Description copied from interface:XMLTagSets the new value on an attribute, and remains on the current tag. If it does not exist, do nothing.- Specified by:
setAttributeIfExistin interfaceXMLTag- Parameters:
name- attribute namevalue- new attribute value- Returns:
- attribute value
-
setAttribute
public XMLTag setAttribute(String name, String value, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSets the new value on a targetted node's attribute, and remains on the current tag.- Specified by:
setAttributein 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(String name, String value, String relativeXpath, Object... arguments) throws XMLDocumentException
Description copied from interface:XMLTagSets 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:
setAttributeIfExistin 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(InputSource source, boolean ignoreNamespaces)
-
from
public static XMLTag from(InputStream is, boolean ignoreNamespaces)
-
fromCurrentTag
public static XMLTag fromCurrentTag(XMLTag tag, boolean ignoreNamespaces)
Create anotherXMLTaginstance 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
-
-