Package oracle.stellent.ridc.common.xml
Class XMLHelper
java.lang.Object
oracle.stellent.ridc.common.xml.XMLHelper
XML Helper methods for working with DOM structures
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TransformerCreate a transformer class with the pretty print flagsstatic StringEncode the string for XML.static intgetAttributeAsInt(Element element, String name, int defaultValue) Retrieve the attribute value as an integerstatic longgetAttributeAsLong(Element element, String name, long defaultValue) Retrieve the attribute value as a longgetAttributes(Element element) Retrieve the attributes from the given element as a mapping of String name to String valuestatic DocumentparseXML(InputStream xmlStream, boolean validating, boolean namespaceAware) Parse xml from the inputstream.static DocumentParse xml from the Reader.static DocumentparseXML(InputSource xmlSource, boolean validating, boolean namespaceAware) Parse xml from InputSource.static voidserialize(Node rootNode, OutputStream out) Pretty prints the XML to the specified output streamstatic voidPretty prints the XML to the specified output streamstatic StringPretty prints the XML and returns it as a stream
-
Field Details
-
AMP_REF
- See Also:
-
APOS_REF
- See Also:
-
GT_REF
- See Also:
-
LT_REF
- See Also:
-
QUOT_REF
- See Also:
-
CHAR_REF_START
- See Also:
-
-
Constructor Details
-
XMLHelper
public XMLHelper()
-
-
Method Details
-
getAttributes
Retrieve the attributes from the given element as a mapping of String name to String value- Parameters:
element- the element- Returns:
- a map of attribute name to attribute value
-
getAttributeAsInt
Retrieve the attribute value as an integer- Parameters:
element- the elementname- the attribute namedefaultValue- the default value- Returns:
- the attribute value or the default if the attribute could not be read or converted to an integer
-
getAttributeAsLong
Retrieve the attribute value as a long- Parameters:
element- the elementname- the attribute namedefaultValue- the default value- Returns:
- the attribute value or the default if the attribute could not be read or converted to a long
-
toString
Pretty prints the XML and returns it as a stream- Parameters:
rootNode- the root node of the XML document to display- Returns:
- the XML display
- Throws:
TransformerException
-
encodeXml
Encode the string for XML. This will escape any reserved characters.- Parameters:
text- the unencoded text- Returns:
- XML-encoded text
-
parseXML
public static Document parseXML(InputStream xmlStream, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException Parse xml from the inputstream.- Parameters:
xmlStream- the stream to the XML contentvalidating- true to validate the XMLnamespaceAware- true to make the parser namespace aware- Returns:
- the Document object
- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
parseXML
public static Document parseXML(Reader xmlReader, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException Parse xml from the Reader.- Parameters:
xmlReader- the reader to the XML contentvalidating- true to validate the XMLnamespaceAware- true to make the parser namespace aware- Returns:
- the Document object
- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
parseXML
public static Document parseXML(InputSource xmlSource, boolean validating, boolean namespaceAware) throws IOException, ParserConfigurationException, SAXException Parse xml from InputSource.- Parameters:
xmlSource- the inputSource to the XML contentvalidating- true to validate the XMLnamespaceAware- true to make the parser namespace aware- Returns:
- the Document object
- Throws:
IOExceptionParserConfigurationExceptionSAXException
-
serialize
Pretty prints the XML to the specified output stream- Parameters:
rootNode- the root node of the XML document to displayout- the output stream- Throws:
TransformerException
-
serialize
Pretty prints the XML to the specified output stream- Parameters:
rootNode- the root node of the XML document to displayout- the output stream- Throws:
TransformerException
-
createPrettyPrintTransformer
Create a transformer class with the pretty print flags- Returns:
- the transformer setup for pretty printing
- Throws:
TransformerException
-