com.mockrunner.util.web
Class XmlUtil

java.lang.Object
  extended by com.mockrunner.util.web.XmlUtil

public class XmlUtil
extends java.lang.Object

Util class for HTML and XML parsing.


Constructor Summary
XmlUtil()
           
 
Method Summary
static org.jdom.Document createJDOMDocument(org.w3c.dom.Document document)
          Creates a JDOM Document from a specified W3C Document.
static java.lang.String createStringFromJDOMDocument(org.jdom.Document document)
          Returns the documents XML content as a string.
static org.jdom.Element getBodyFragmentFromJDOMDocument(org.jdom.Document document)
          Convinience method for HTML fragments.
static org.jdom.Element getBodyFragmentJDOMDocument(org.jdom.Document document)
          Deprecated. use getBodyFragmentFromJDOMDocument(org.jdom.Document)
static org.apache.xerces.parsers.DOMParser getHTMLParser()
          Returns a parser suitable for parsing HTML documents.
static org.w3c.dom.Document parse(org.apache.xerces.parsers.DOMParser parser, java.lang.String source)
          Parses the specified XML with the specified parser.
static org.w3c.dom.Document parseHTML(java.lang.String source)
          Parses the specified HTML with the NekoHTML parser.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XmlUtil

public XmlUtil()
Method Detail

getBodyFragmentFromJDOMDocument

public static org.jdom.Element getBodyFragmentFromJDOMDocument(org.jdom.Document document)
Convinience method for HTML fragments. Returns the body as JDOM Element. If an HTML documents looks like this:
 <html>
 <head>
 </head>
 <body>
 <h1>
 </h1>
 </body>
 </html>
 
the method returns the h1 tag as Element.

Parameters:
document - the org.jdom.Document
Returns:
the body Element

getBodyFragmentJDOMDocument

public static org.jdom.Element getBodyFragmentJDOMDocument(org.jdom.Document document)
Deprecated. use getBodyFragmentFromJDOMDocument(org.jdom.Document)


createStringFromJDOMDocument

public static java.lang.String createStringFromJDOMDocument(org.jdom.Document document)
Returns the documents XML content as a string.

Parameters:
document - the org.jdom.Document
Returns:
the output as string

createJDOMDocument

public static org.jdom.Document createJDOMDocument(org.w3c.dom.Document document)
Creates a JDOM Document from a specified W3C Document.

Parameters:
document - the org.w3c.dom.Document
Returns:
the org.jdom.Document

getHTMLParser

public static org.apache.xerces.parsers.DOMParser getHTMLParser()
Returns a parser suitable for parsing HTML documents. The NekoHTML parser is used with some settings to preserve case of tag names and disable namespace processing. This method is used by parseHTML(java.lang.String).

Returns:
instance of org.apache.xerces.parsers.DOMParser with Neko configuration

parseHTML

public static org.w3c.dom.Document parseHTML(java.lang.String source)
Parses the specified HTML with the NekoHTML parser. If you want to use another HTML parser or configure the NekoHTML parser with special features, you can use the parse method.

Parameters:
source - the HTML as String
Returns:
the parsed document as org.w3c.dom.Document

parse

public static org.w3c.dom.Document parse(org.apache.xerces.parsers.DOMParser parser,
                                         java.lang.String source)
Parses the specified XML with the specified parser. The main purpose of this method is to use the NekoHTML parser with custom features and properties. If you can live with the settings provided by Mockrunner, you can use parseHTML(java.lang.String).

Parameters:
parser - the parser (must extend org.apache.xerces.parsers.DOMParser), e.g. the one returned by getHTMLParser()
source - the XML as String
Returns:
the parsed document as org.w3c.dom.Document