public class XmlHelper extends Object
| 构造器和说明 |
|---|
XmlHelper() |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addAttribute(org.dom4j.Element Element,
String AttributeName,
String AttributeValue)
Add the attribute name and value under specified element
|
org.dom4j.Element |
addChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
Add a element under specified parent element
|
void |
addComment(org.dom4j.Element Element,
String strComment)
Add the specified comment under specified element
|
void |
applyXSL(String strInXMLFileName,
String strXSLFileName,
String strOutHTMLFileName)
Transform XML to HTML
|
void |
createDocument()
Create the instance of the Document class
|
org.dom4j.Element |
createDocumentRoot(String strRootName)
Create a root element for object document
|
void |
createProcessingInstruction(String strProcessingInstructionName,
String strProcessingInstructionValue)
Create the Processing Instruction
|
org.dom4j.Attribute |
findAttributeByXPath(String xpath)
Get attribute by XPath
|
org.dom4j.Element |
findElementByXPath(String xpath)
Get element by XPath
|
List<org.dom4j.Element> |
findElementsByXPath(String xpath)
Find elements by x path list.
|
void |
getAllDifferences(String xml1,
String xml2)
Gets all differences.
|
org.dom4j.Attribute |
getAttribute(org.dom4j.Element element,
String strAttributeNmae)
Get the attribute of the specified element
|
String |
getAttributeText(org.dom4j.Element element,
String strAttributeNmae)
Get the attribute text of the specified element
|
org.dom4j.Element |
getChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
Get the specified child element
|
List<org.dom4j.Element> |
getChildElements(org.dom4j.Element ParentElement,
String strElementNmae)
Get the specified child element
|
String |
getChildText(org.dom4j.Element ParentElement,
String strElementNmae)
Get the text of the specified child element
|
int |
getDiffCount(String xml1,
String xml2)
Get the number of the difference
|
org.dom4j.Document |
getDocument()
Gets document.
|
org.dom4j.Element |
getRootElement()
Get the root element
|
String |
getText(org.dom4j.Element element)
Get the text of the specified element
|
boolean |
isIdentical(String xml1,
String xml2)
Two XML documents are considered to be "identical" if they contain the
same elements and attributes in the same order.
|
boolean |
isSimilar(String xml1,
String xml2)
Two documents are considered to be "similar" if they contain the same
elements and attributes regardless of order.
|
void |
iterateElements(String xpath,
HashMap<String,String> hm)
Iterate all elements under specified parent element and put the element
name and element text into HashMap
|
org.dom4j.Document |
readXMLFile(String sFileName)
Read and parse XML file
|
void |
removeAttribute(org.dom4j.Element Element,
String strAttributeNmae)
Remove the specified Attribute under specified element
|
void |
removeChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
Remove the specified child Element under Parent element
|
void |
saveTo(String strFileName)
Save document to specified XML file
|
void |
setAttributeText(org.dom4j.Element element,
String strAttributeNmae,
String strAttributeValue)
Set the attribute text of the specified element
|
void |
setDocument(org.dom4j.Document document)
Sets document.
|
void |
setText(org.dom4j.Element Element,
String strText)
Set the element text for the specified element
|
XmlHelper |
strToXML(String str)
Str to xml xml helper.
|
public org.dom4j.Document getDocument()
public void setDocument(org.dom4j.Document document)
document - the documentpublic XmlHelper strToXML(String str)
str - the strpublic void createDocument()
public void createProcessingInstruction(String strProcessingInstructionName, String strProcessingInstructionValue) throws org.dom4j.DocumentException
strProcessingInstructionName - the str processing instruction namestrProcessingInstructionValue - the str processing instruction valueorg.dom4j.DocumentException - the document exceptionpublic org.dom4j.Element createDocumentRoot(String strRootName)
strRootName - the root element name to be createdpublic org.dom4j.Element addChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
ParentElement - specified parent elementstrElementNmae - the element name to be addedpublic void setText(org.dom4j.Element Element,
String strText)
Element - the elementstrText - the text to be setpublic void addAttribute(org.dom4j.Element Element,
String AttributeName,
String AttributeValue)
Element - the elementAttributeName - the attribute nameAttributeValue - the attribute valuepublic void addComment(org.dom4j.Element Element,
String strComment)
Element - the elementstrComment - the str commentpublic void removeChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
ParentElement - the parent elementstrElementNmae - the element name to be removedpublic void removeAttribute(org.dom4j.Element Element,
String strAttributeNmae)
Element - the elementstrAttributeNmae - the attribute name to be removedpublic void saveTo(String strFileName)
strFileName - the XML file name to be savedpublic org.dom4j.Document readXMLFile(String sFileName)
sFileName - The full path of the XML filepublic org.dom4j.Element getRootElement()
public org.dom4j.Element getChildElement(org.dom4j.Element ParentElement,
String strElementNmae)
ParentElement - the parent elementstrElementNmae - the str element nmaepublic List<org.dom4j.Element> getChildElements(org.dom4j.Element ParentElement, String strElementNmae)
ParentElement - the parent elementstrElementNmae - the str element nmaepublic String getText(org.dom4j.Element element)
element - the elementpublic String getChildText(org.dom4j.Element ParentElement, String strElementNmae)
ParentElement - the parent elementstrElementNmae - the str element nmaepublic org.dom4j.Attribute getAttribute(org.dom4j.Element element,
String strAttributeNmae)
element - the elementstrAttributeNmae - the str attribute nmaepublic String getAttributeText(org.dom4j.Element element, String strAttributeNmae)
element - the elementstrAttributeNmae - the str attribute nmaepublic void setAttributeText(org.dom4j.Element element,
String strAttributeNmae,
String strAttributeValue)
element - the elementstrAttributeNmae - the str attribute nmaestrAttributeValue - the str attribute valuepublic org.dom4j.Element findElementByXPath(String xpath)
xpath - such as /company/department[name = 'HR']/employee[1]public List<org.dom4j.Element> findElementsByXPath(String xpath)
xpath - the xpathpublic org.dom4j.Attribute findAttributeByXPath(String xpath)
xpath - such as /company/department[name = 'HR']/employee[1]/@salarypublic void iterateElements(String xpath, HashMap<String,String> hm)
xpath - the xpathhm - the hmpublic void applyXSL(String strInXMLFileName, String strXSLFileName, String strOutHTMLFileName)
strInXMLFileName - the str in xml file namestrXSLFileName - the str xsl file namestrOutHTMLFileName - the str out html file namepublic boolean isSimilar(String xml1, String xml2)
xml1 - the xml 1xml2 - the xml 2public boolean isIdentical(String xml1, String xml2)
xml1 - the xml 1xml2 - the xml 2public void getAllDifferences(String xml1, String xml2) throws SAXException, IOException
xml1 - the xml 1xml2 - the xml 2SAXException - the sax exceptionIOException - the io exceptionpublic int getDiffCount(String xml1, String xml2) throws SAXException, IOException
xml1 - the xml 1xml2 - the xml 2SAXException - the sax exceptionIOException - the io exceptionCopyright © 2017. All rights reserved.