public final class DomUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static String |
addFolderSlashIfNeeded(String folderName)
Adds a slash to a path if it doesn't end with a slash.
|
static Document |
asDocument(String html)
transforms a string into a Document object.
|
static String |
getAllElementAttributes(Element element) |
static List<org.custommonkey.xmlunit.Difference> |
getDifferences(String controlDom,
String testDom)
Get differences between doms.
|
static List<org.custommonkey.xmlunit.Difference> |
getDifferences(String controlDom,
String testDom,
List<String> ignoreAttributes)
Get differences between doms.
|
static Document |
getDocumentNoBalance(String html) |
static byte[] |
getDocumentToByteArray(Document dom)
Serialize the Document object.
|
static String |
getDocumentToString(Document dom) |
static String |
getElementAttributes(Element element,
com.google.common.collect.ImmutableSet<String> exclude) |
static Element |
getElementByXpath(Document dom,
String xpath) |
static String |
getElementString(Element element) |
static String |
getFrameIdentification(Element frame) |
static String |
getJSGetElement(String xpath) |
static String |
getTemplateAsString(String fname)
Retrieves the content of the filename.
|
static String |
getTextValue(Element element)
Returns the text value of an element (title, alt or contents).
|
static String |
removeNewLines(String html)
Removes newlines from a string.
|
static Document |
removeScriptTags(Document dom)
Removes all the tags from the document.
|
static Document |
removeTags(Document dom,
String tagName)
Removes all the given tags from the document.
|
static String |
replaceString(String string,
String regex,
String replace) |
static void |
writeDocumentToFile(Document document,
String filePathname,
String method,
int indent)
Write the document object to a file.
|
public static Document asDocument(String html) throws IOException
html - the HTML string.IOException - if an IO failure occurs.SAXException - if an exception occurs while parsing the HTML string.public static Document getDocumentNoBalance(String html) throws SAXException, IOException
html - the HTML string.SAXException - if an exception occurs while parsing the HTML string.IOException - if an IO failure occurs.public static String getAllElementAttributes(Element element)
element - The DOM Element.public static String getElementAttributes(Element element, com.google.common.collect.ImmutableSet<String> exclude)
element - The DOM Element.exclude - the list of exclude strings.public static String getElementString(Element element)
element - the element.public static Element getElementByXpath(Document dom, String xpath) throws XPathExpressionException
dom - the DOM document.xpath - the xpath.XPathExpressionException - if the xpath fails.public static Document removeScriptTags(Document dom)
dom - the document object.public static Document removeTags(Document dom, String tagName)
dom - the document object.tagName - the tag name, examples: script, style, metapublic static String getDocumentToString(Document dom)
dom - the DOM document.public static byte[] getDocumentToByteArray(Document dom)
dom - the document to serializepublic static String getTextValue(Element element)
element - The element.public static List<org.custommonkey.xmlunit.Difference> getDifferences(String controlDom, String testDom)
controlDom - The control dom.testDom - The test dom.public static List<org.custommonkey.xmlunit.Difference> getDifferences(String controlDom, String testDom, List<String> ignoreAttributes)
controlDom - The control dom.testDom - The test dom.ignoreAttributes - The list of attributes to ignore.public static String removeNewLines(String html)
html - The string.public static String replaceString(String string, String regex, String replace)
string - The original string.regex - The regular expression.replace - What to replace it with.public static String addFolderSlashIfNeeded(String folderName)
folderName - The path to append a possible slash.public static String getTemplateAsString(String fname) throws IOException
fname - Filename.IOException - On error.public static String getJSGetElement(String xpath)
xpath - The xpath of the element.public static String getFrameIdentification(Element frame)
frame - the frame element.public static void writeDocumentToFile(Document document, String filePathname, String method, int indent) throws TransformerException, IOException
document - the document object.filePathname - the path name of the file to be written to.method - the output method: for instance html, xml, textindent - amount of indentation. -1 to use the default.TransformerException - if an exception occurs.IOException - if an IO exception occurs.Copyright © 2007-2013. All Rights Reserved.