public class XMLParser extends Object
String filename = "c:\\a.xml";
String xpath = "/Domain";
try
{
XMLParser parser = new XMLParser( filename );
parser.addElementToElement( xpath, "component" );
parser.addAttributeToElement( xpath + "/component", "name", "libraryTable" );
parser.addElementToElement( xpath + "/component", "CLASSES" );
parser.addElementToElement( xpath + "/component/CLASSES", "root" );
parser.addAttributeToElement( xpath + "/component/CLASSES/root", "url", "jar://C:/castor.jar!/" );
parser.commit();
}
catch ( Exception e )
{
// handle error
}
| Modifier and Type | Field and Description |
|---|---|
static String |
ISO_8859_1 |
| Constructor and Description |
|---|
XMLParser(File file) |
XMLParser(InputStream file)
Constructor for XMLParser
Use this constructor only for read actions (not for write)
|
XMLParser(String fileName)
Constructor for XMLParser
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttributeToElement(String xpathString,
String name,
String value)
Add an Attribute to a node
|
void |
addElementAfterElement(String xpathString,
String element,
String value)
Adds an element after an element
|
void |
addElementAfterElement(String xpathString,
String element,
String value,
String attributeName,
String attributeValue)
Adds an element after an element
|
void |
addElementToElement(String xpathString,
String element)
Add an Element to a node
|
void |
addElementToElement(String xpathString,
String element,
String value)
Add an Element to a node
|
void |
addElementToElement(String xpathString,
String element,
String value,
String attributeName,
String attributeValue)
Adds an element to an element
|
void |
appendNode(String xpathString,
Node node)
Appends the node to the childList
of the node given by the xpath
|
void |
commit()
Commit a set operation to the xml file
|
void |
commitWithDTD(String dtdFile)
Commits with a DTD
|
String |
getCharset()
Gets the character set
|
Indentation |
getIndentation()
Gets the indentation
|
Node |
getNode(String xpathString)
Gets the Node
|
List<Node> |
getNodeList(String xpathString)
Gets the node list
|
List<String> |
getNodesAttributes(String xpathString,
String attributeName)
Gets attributes matched under xpathString and having name attribute name
|
List<String> |
getNodesValue(String xpathString)
Gets the value of a node from an XPath
|
String |
getNodeValue(String xpathString)
Get a node value
|
void |
removeNode(String xpathString)
Remove a Node
|
void |
setCharset(String charset)
Sets the character set
|
void |
setIndentation(Indentation indentation)
Sets the indentation
|
void |
updateNodesValue(String xpathString,
List<String> values)
Updates a node's value
|
void |
updateNodeValue(String xpathString,
String value)
Update a node value
|
public static final String ISO_8859_1
public XMLParser(String fileName) throws Exception
fileName - XML file to parseException - for any errorspublic XMLParser(InputStream file) throws Exception
file - XML file to parseException - for any errorspublic Indentation getIndentation()
public void setIndentation(Indentation indentation)
indentation - indentationpublic String getCharset()
public void setCharset(String charset)
charset - character setpublic List<Node> getNodeList(String xpathString) throws Exception
xpathString - XPath expressionException - for any errorspublic List<String> getNodesValue(String xpathString) throws Exception
xpathString - XPath expressionException - for any errorspublic List<String> getNodesAttributes(String xpathString, String attributeName) throws Exception
xpathString - XPath expressionattributeName - attribute nameException - for any errorspublic String getNodeValue(String xpathString) throws Exception
xpathString - XPath expressionException - for any errorspublic void updateNodesValue(String xpathString, List<String> values) throws Exception
xpathString - XPath expressionvalues - values to replace matches returned by xpathStringException - for any errorspublic void updateNodeValue(String xpathString, String value) throws Exception
xpathString - XPath expressionvalue - the new value for the nodeException - for any errorspublic void addAttributeToElement(String xpathString, String name, String value) throws Exception
xpathString - XPath expressionname - attribute namevalue - attribute valueException - for any errorspublic void addElementToElement(String xpathString, String element) throws Exception
xpathString - XPath expressionelement - elementException - for any errorspublic void addElementToElement(String xpathString, String element, String value) throws Exception
xpathString - XPath expressionelement - elementvalue - new value for the new nodeException - for any errorspublic void addElementToElement(String xpathString, String element, String value, String attributeName, String attributeValue) throws Exception
xpathString - XPath expressionelement - elementvalue - valueattributeName - attribute nameattributeValue - attribute valueException - for any errorspublic void addElementAfterElement(String xpathString, String element, String value) throws Exception
xpathString - XPath expressionelement - elementvalue - valueException - for any errorspublic void addElementAfterElement(String xpathString, String element, String value, String attributeName, String attributeValue) throws Exception
xpathString - XPath expressionelement - elementvalue - valueattributeName - attribute nameattributeValue - attribute valueException - for any errorspublic void appendNode(String xpathString, Node node) throws Exception
xpathString - XPath expressionnode - Node to appendException - for any errorspublic Node getNode(String xpathString) throws Exception
xpathString - XPath expressionException - for any errorspublic void removeNode(String xpathString) throws Exception
xpathString - XPath expressionException - for any errorspublic void commit()
public void commitWithDTD(String dtdFile)
dtdFile - DTD file? Copyright 2013 BMC Software, Inc.