public class XMLHelper extends Object
Modifier and Type | Field and Description |
---|---|
protected static String |
AMP_REF |
protected static String |
APOS_REF |
protected static String |
CHAR_REF_START |
protected static String |
GT_REF |
protected static String |
LT_REF |
protected static String |
QUOT_REF |
Constructor and Description |
---|
XMLHelper() |
Modifier and Type | Method and Description |
---|---|
static Transformer |
createPrettyPrintTransformer()
Create a transformer class with the pretty print flags
|
static String |
encodeXml(String text)
Encode the string for XML.
|
static int |
getAttributeAsInt(Element element,
String name,
int defaultValue)
Retrieve the attribute value as an integer
|
static long |
getAttributeAsLong(Element element,
String name,
long defaultValue)
Retrieve the attribute value as a long
|
static Map<String,String> |
getAttributes(Element element)
Retrieve the attributes from the given element as a mapping of String name to String value
|
static Document |
parseXML(InputSource xmlSource,
boolean validating,
boolean namespaceAware)
Parse xml from InputSource.
|
static Document |
parseXML(InputStream xmlStream,
boolean validating,
boolean namespaceAware)
Parse xml from the inputstream.
|
static Document |
parseXML(Reader xmlReader,
boolean validating,
boolean namespaceAware)
Parse xml from the Reader.
|
static void |
serialize(Node rootNode,
OutputStream out)
Pretty prints the XML to the specified output stream
|
static void |
serialize(Node rootNode,
Writer out)
Pretty prints the XML to the specified output stream
|
static String |
toString(Node rootNode)
Pretty prints the XML and returns it as a stream
|
protected static final String AMP_REF
protected static final String APOS_REF
protected static final String GT_REF
protected static final String LT_REF
protected static final String QUOT_REF
protected static final String CHAR_REF_START
public static Map<String,String> getAttributes(Element element)
element
- the elementpublic static int getAttributeAsInt(Element element, String name, int defaultValue)
element
- the elementname
- the attribute namedefaultValue
- the default valuepublic static long getAttributeAsLong(Element element, String name, long defaultValue)
element
- the elementname
- the attribute namedefaultValue
- the default valuepublic static String toString(Node rootNode) throws TransformerException
rootNode
- the root node of the XML document to displayTransformerException
public static String encodeXml(String text)
text
- the unencoded textpublic static Document parseXML(InputStream xmlStream, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException
xmlStream
- the stream to the XML contentvalidating
- true to validate the XMLnamespaceAware
- true to make the parser namespace awareIOException
ParserConfigurationException
SAXException
public static Document parseXML(Reader xmlReader, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException
xmlReader
- the reader to the XML contentvalidating
- true to validate the XMLnamespaceAware
- true to make the parser namespace awareIOException
ParserConfigurationException
SAXException
public static Document parseXML(InputSource xmlSource, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException
xmlSource
- the inputSource to the XML contentvalidating
- true to validate the XMLnamespaceAware
- true to make the parser namespace awareIOException
ParserConfigurationException
SAXException
public static void serialize(Node rootNode, OutputStream out) throws TransformerException
rootNode
- the root node of the XML document to displayout
- the output streamTransformerException
public static void serialize(Node rootNode, Writer out) throws TransformerException
rootNode
- the root node of the XML document to displayout
- the output streamTransformerException
public static Transformer createPrettyPrintTransformer() throws TransformerException
TransformerException