public class XMLDocument extends Object
Constructor and Description |
---|
XMLDocument() |
XMLDocument(String sFile)
Create XMLDocument and load an XML file into memory.
|
XMLDocument(String sFile,
String sEnc)
Create XMLDocument and load an XML file into memory.
|
Modifier and Type | Method and Description |
---|---|
void |
addNode(String sAfterXPath,
String sNode)
Add a piece of XML text after a given node identifier by an XPath expression.
|
void |
addNodeAndSave(String sAfterXPath,
String sNode)
Add a piece of XML text after a given node and save document.
|
String |
getCharacterEncoding() |
void |
load(String sFile)
Load an XML file into memory.
|
void |
load(String sFile,
String sEnc)
Load an XML file into memory.
|
void |
removeNode(String sXPath)
Remove a node.
|
void |
removeNodeAndSave(String sXPath)
Remove a node and save document.
|
void |
save()
Save file to disk.
|
void |
save(String sFile)
Save file to disk.
|
void |
setCharacterEncoding(String sEnc) |
String |
toString()
Get loaded file as a String
|
public XMLDocument()
public XMLDocument(String sFile) throws IOException, OutOfMemoryError
Create XMLDocument and load an XML file into memory.
No node parsing is done, but file is loaded directly into a String.sFile
- File PathIOException
OutOfMemoryError
public XMLDocument(String sFile, String sEnc) throws IOException, OutOfMemoryError
sFile
- File PathsEnc
- Character EncodingIOException
OutOfMemoryError
public String getCharacterEncoding()
public void setCharacterEncoding(String sEnc)
public void load(String sFile, String sEnc) throws IOException, OutOfMemoryError
sFile
- File PathsEnc
- Character encodingIOException
OutOfMemoryError
public void load(String sFile) throws IOException, OutOfMemoryError
Load an XML file into memory.
No node parsing is done, but file is loaded directly into a String.sFile
- File PathIOException
OutOfMemoryError
public void save(String sFile) throws IOException
sFile
- File PathIOException
public void save() throws IOException
IOException
public void addNode(String sAfterXPath, String sNode) throws DOMException
sAfterXPath
- Restricted XPath expression for node after witch the next node is to be placed.
For example : sNode
- XML Text to be added.DOMException
- DOMException Codes:NOT_FOUND_ERR | A node or attribute from the XPath expression was not found |
INVALID_ACCESS_ERR | An attribute expression is invalid |
NOT_SUPPORTED_ERR | position() function was used but last() was not specified as value for it |
public void addNodeAndSave(String sAfterXPath, String sNode) throws DOMException, IOException
sAfterXPath
- Restricted XPath expression for node after witch the next node is to be placed.sNode
- XML Text to be added.DOMException
IOException
public void removeNode(String sXPath) throws DOMException
sXPath
- Restricted XPath expression for node to remove.
For example: "pageset/pages/page[@guid="123456789012345678901234567890AB"]/blocks/block[@id="003"]"
will remove <block id="003">…</block> substring.DOMException
public void removeNodeAndSave(String sXPath) throws DOMException, IOException
sXPath
- XPath expression for node to remove.DOMException
IOException
Copyright © 2019. All rights reserved.