Package com.github.simy4.xpath
Class XmlBuilder
- java.lang.Object
-
- com.github.simy4.xpath.XmlBuilder
-
- All Implemented Interfaces:
java.io.Serializable
public class XmlBuilder extends java.lang.Object implements java.io.Serializable
XML model modifier that works via XPath expressions processing.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description XmlBuilder()
XmlBuilder(javax.xml.namespace.NamespaceContext namespaceContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
build(T xml)
Evaluates collected XPath effects on a given XML model object.static boolean
canHandle(java.lang.Object xml)
Checks whetherXmlBuilder
supports given XML model.XmlBuilder
put(java.lang.String xpath)
Greedily creates all missing nodes that could be evaluated by given XPath expression.XmlBuilder
put(java.lang.String xpath, java.lang.Object value)
Greedily creates all missing nodes that could be evaluated by given XPath expression and then sets given value as text content to all evaluated nodes.XmlBuilder
putAll(java.lang.Iterable<java.lang.String> xpaths)
Greedily creates all missing nodes that could be evaluated by given XPath expressions.XmlBuilder
putAll(java.lang.String... xpaths)
Greedily creates all missing nodes that could be evaluated by given XPath expressions.XmlBuilder
putAll(java.util.Map<java.lang.String,java.lang.Object> xpathToValueMap)
Greedily creates all missing nodes that could be evaluated by given XPath expressions and then sets the associated value as text content to all evaluated nodes.XmlBuilder
remove(java.lang.String xpath)
Evaluates given XPath expression and detaches all of the resulting nodes.XmlBuilder
removeAll(java.lang.Iterable<java.lang.String> xpaths)
Evaluates given XPath expressions and detaches all of the resulting nodes.XmlBuilder
removeAll(java.lang.String... xpaths)
Evaluates given XPath expressions and detaches all of the resulting nodes.
-
-
-
Method Detail
-
canHandle
public static boolean canHandle(java.lang.Object xml)
Checks whetherXmlBuilder
supports given XML model.- Parameters:
xml
- XML to check- Returns:
true
if it can handle given model orfalse
otherwise
-
put
public XmlBuilder put(java.lang.String xpath) throws javax.xml.xpath.XPathExpressionException
Greedily creates all missing nodes that could be evaluated by given XPath expression.- Parameters:
xpath
- XPath to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
putAll(Iterable)
-
put
public XmlBuilder put(java.lang.String xpath, java.lang.Object value) throws javax.xml.xpath.XPathExpressionException
Greedily creates all missing nodes that could be evaluated by given XPath expression and then sets given value as text content to all evaluated nodes.- Parameters:
xpath
- XPath to processvalue
- value to set- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
putAll(Map)
-
putAll
public XmlBuilder putAll(java.lang.String... xpaths) throws javax.xml.xpath.XPathExpressionException
Greedily creates all missing nodes that could be evaluated by given XPath expressions.- Parameters:
xpaths
- XPaths to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
putAll(Iterable)
-
putAll
public XmlBuilder putAll(java.lang.Iterable<java.lang.String> xpaths) throws javax.xml.xpath.XPathExpressionException
Greedily creates all missing nodes that could be evaluated by given XPath expressions.- Parameters:
xpaths
- XPaths to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
put(String)
,putAll(String...)
-
putAll
public XmlBuilder putAll(java.util.Map<java.lang.String,java.lang.Object> xpathToValueMap) throws javax.xml.xpath.XPathExpressionException
Greedily creates all missing nodes that could be evaluated by given XPath expressions and then sets the associated value as text content to all evaluated nodes.- Parameters:
xpathToValueMap
- XPath to values associations- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
put(String, Object)
-
remove
public XmlBuilder remove(java.lang.String xpath) throws javax.xml.xpath.XPathExpressionException
Evaluates given XPath expression and detaches all of the resulting nodes.- Parameters:
xpath
- XPath to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
removeAll(Iterable)
-
removeAll
public XmlBuilder removeAll(java.lang.String... xpaths) throws javax.xml.xpath.XPathExpressionException
Evaluates given XPath expressions and detaches all of the resulting nodes.- Parameters:
xpaths
- XPaths to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
removeAll(Iterable)
-
removeAll
public XmlBuilder removeAll(java.lang.Iterable<java.lang.String> xpaths) throws javax.xml.xpath.XPathExpressionException
Evaluates given XPath expressions and detaches all of the resulting nodes.- Parameters:
xpaths
- XPaths to process- Returns:
XmlBuilder
instance- Throws:
javax.xml.xpath.XPathExpressionException
- if xpath cannot be parsed- See Also:
remove(String)
,removeAll(String...)
-
build
public <T> T build(T xml) throws XmlBuilderException
Evaluates collected XPath effects on a given XML model object.- Type Parameters:
T
- XML model type- Parameters:
xml
- XML to process- Returns:
- processing result
- Throws:
XmlBuilderException
- if XML model modification failed
-
-