public class XMLReader extends Object
Constructor and Description |
---|
XMLReader(String file)
Constructs the XML reader.
|
XMLReader(String file,
boolean useFabanNS,
boolean warnDeprecated)
Constructs the XML reader.
|
Modifier and Type | Method and Description |
---|---|
Element |
addNode(Element parent,
String namespaceURI,
String prefix,
String nodeName)
Adds a node.
|
Element |
addNode(String baseXPath,
String namespaceURI,
String prefix,
String nodeName)
Adds a node.
|
void |
deleteNode(Node deleteNode,
Node parent)
Deletes a node.
|
List<String> |
getAttributeValues(String xpath,
String attribute)
Returns the list of attribute values for a given xpath and attribute.
|
List<String> |
getAttributeValues(String xpath,
String attribute,
Node base)
Returns the list of attribute values for a given xpath and attribute
based on base node.
|
List<NameValuePair<Integer>> |
getHostPorts(Element roleNode)
Obtains the host:port pairs based on a role.
|
List<NameValuePair<Integer>> |
getHostPorts(String xPathExpr)
Obtains the host:port name value pair list from the element
matching this XPath.
|
Node |
getNode(String xpath)
Returns node for the given xpath.
|
Node |
getNode(String xpath,
Node base)
Returns node for the given xpath based on the base node.
|
NodeList |
getNodeList(String xPathExpr)
Returns NodeList for a given xpath string.
|
NodeList |
getNodeListForTagName(String tagName)
Returns nodelist for the given tag.
|
NodeList |
getNodes(String xpath)
Returns the nodelist for a given xpath.
|
NodeList |
getNodes(String xpath,
Node base)
Returns the nodelist for a given xpath based on a base node.
|
Element |
getRootNode()
Returns the root element.
|
NodeList |
getTopLevelElements()
Returns nodelist for top level elements(Children of root element).
|
String |
getValue(String xpath)
Returns the value for the given xpath.
|
String |
getValue(String xpath,
Node base)
Returns the value for the given xpath based on the base node.
|
List<String> |
getValues(String xpath)
Returns the list of values for a given xpath.
|
List<String> |
getValues(String xpath,
Node base)
Returns the list of values for a given xpath based on base node.
|
static void |
main(String[] args)
Runs some testing of the XML reader.
|
void |
processHostPorts()
Scans the XML for specific entries matching
"//fa:hostConfig/fa:hostPorts" and processes them for later retrieval.
|
void |
replaceValue(Element element,
String value)
Replaces the new value for the element text.
|
boolean |
save(String backupFileName)
This method saves the XML file if it was modified
and if a back up file name is specified the original
file is backed up.
|
void |
setValue(Element element,
String value)
Sets the new value for the element.
|
void |
setValue(String xpath,
String newValue)
Sets the new value for a given xpath.
|
public XMLReader(String file)
file
- The XML filepublic XMLReader(String file, boolean useFabanNS, boolean warnDeprecated)
file
- The XML fileuseFabanNS
- Whether to apply Faban namespaces in this filewarnDeprecated
- Whether to warn for deprecated Faban elementspublic NodeList getNodeListForTagName(String tagName)
tagName
- public NodeList getTopLevelElements()
public Element getRootNode()
public Node getNode(String xpath)
xpath
- public Node getNode(String xpath, Node base)
xpath
- base
- public NodeList getNodes(String xpath)
xpath
- public NodeList getNodes(String xpath, Node base)
xpath
- base
- public String getValue(String xpath)
xpath
- public String getValue(String xpath, Node base)
xpath
- base
- public List<String> getValues(String xpath)
xpath
- public List<String> getValues(String xpath, Node base)
xpath
- base
- public List<String> getAttributeValues(String xpath, String attribute)
xpath
- attribute
- public List<String> getAttributeValues(String xpath, String attribute, Node base)
xpath
- attribute
- base
- public void setValue(String xpath, String newValue)
xpath
- The XPath to the element to set the valuenewValue
- The new valuepublic void setValue(Element element, String value)
element
- The DOM elementvalue
- The new valuepublic void replaceValue(Element element, String value)
element
- value
- public void deleteNode(Node deleteNode, Node parent)
deleteNode
- parent
- public Element addNode(Element parent, String namespaceURI, String prefix, String nodeName)
parent
- namespaceURI
- prefix
- nodeName
- public Element addNode(String baseXPath, String namespaceURI, String prefix, String nodeName)
baseXPath
- namespaceURI
- prefix
- nodeName
- public boolean save(String backupFileName) throws Exception
backupFileName
- - the name of the backup fileException
- Error saving the filepublic void processHostPorts()
public List<NameValuePair<Integer>> getHostPorts(String xPathExpr)
xPathExpr
- public List<NameValuePair<Integer>> getHostPorts(Element roleNode)
roleNode
- The node representing the rolepublic NodeList getNodeList(String xPathExpr)
xPathExpr
-