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.SerializableXML 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> Tbuild(T xml)Evaluates collected XPath effects on a given XML model object.static booleancanHandle(java.lang.Object xml)Checks whetherXmlBuildersupports given XML model.XmlBuilderput(java.lang.String xpath)Greedily creates all missing nodes that could be evaluated by given XPath expression.XmlBuilderput(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.XmlBuilderputAll(java.lang.Iterable<java.lang.String> xpaths)Greedily creates all missing nodes that could be evaluated by given XPath expressions.XmlBuilderputAll(java.lang.String... xpaths)Greedily creates all missing nodes that could be evaluated by given XPath expressions.XmlBuilderputAll(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.XmlBuilderremove(java.lang.String xpath)Evaluates given XPath expression and detaches all of the resulting nodes.XmlBuilderremoveAll(java.lang.Iterable<java.lang.String> xpaths)Evaluates given XPath expressions and detaches all of the resulting nodes.XmlBuilderremoveAll(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 whetherXmlBuildersupports given XML model.- Parameters:
xml- XML to check- Returns:
trueif it can handle given model orfalseotherwise
-
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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- 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:
XmlBuilderinstance- Throws:
javax.xml.xpath.XPathExpressionException- if xpath cannot be parsed- See Also:
remove(String),removeAll(String...)
-
build
public <T> T build(T xml) throws XmlBuilderExceptionEvaluates 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
-
-