XMLUtils

From GreenVulcano Wiki
Revision as of 20:07, 13 February 2012 by G.dimaio (talk | contribs) (Created page with "Class FQN: '''it.greenvulcano.util.xml.XMLUtils''' ==Following the Class public static methods== * Parsing <syntaxhighlight lang="java5"> /** * Returns a DOM parsed from the giv...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Class FQN: it.greenvulcano.util.xml.XMLUtils

Following the Class public static methods

  • Parsing
/**
* Returns a DOM parsed from the given XML string.
*
* @param xmlString
*        A String containing an XML document
* @param isValidating
* @param isNamespaceAware
* @return The corresponding DOM
* @throws XMLUtilsException
*         when errors occur
*/
public static Document parseDOM_S(String xmlString) throws XMLUtilsException

/**
* Returns a DOM parsed from the given XML string.
*
* @param xmlString
*        A String containing an XML document
* @param isValidating
* @param isNamespaceAware
* @return The corresponding DOM
* @throws XMLUtilsException
*         when errors occur
*/
public static Document parseDOM_S(String xmlString, boolean isValidating, boolean isNamespaceAware) throws XMLUtilsException

/**
* Returns a DOM parsed from the given XML input stream.
*
* @param xmlStream
*        input document
* @param isValidating
*        if true try to validating the XML
* @param isNamespaceAware
*        if true ability to resolver namespace
* @return a DOM parsed from the given XML input stream.
* @throws XMLUtilsException
*/
public static Document parseDOM_S(InputStream xmlStream, boolean isValidating, boolean isNamespaceAware) throws XMLUtilsException

/**
* Returns a DOM parsed from the given byte array.
*
* @param xml
*        A byte array containing an XML document
* @param isValidating
* @param isNamespaceAware
* @return The corresponding DOM
* @throws XMLUtilsException
*         when errors occur
*/
public static Document parseDOM_S(byte[] xml, boolean isValidating, boolean isNamespaceAware) throws XMLUtilsException

/**
* Returns a DOM parsed from the given input object.
*
* @param object
*        input object (Document, Node, String serialized XML, byte[] serialized XML, InputStream)
* @param isValidating
*        if true try to validating the XML
* @param isNamespaceAware
*        if true ability to resolver namespace
* @return a DOM parsed from the given input object.
* @throws XMLUtilsException
*/
public static Document parseObject_S(Object input, boolean isValidating, boolean isNamespaceAware) throws XMLUtilsException

/**
* Parses the DOM document and validates it.
*
* @param type
* @param docStream
*        the XML document do parse
* @param gvEntityResolver
* @param gvErrorHandler
* @return the document parsed
*
* @throws XMLUtilsException
*/
public static Document parseDOMValidating(String type, InputStream docStream, EntityResolver gvEntityResolver, ErrorHandler gvErrorHandler) throws XMLUtilsException
  • Serialization
/**
* Serialize a given DOM to an XML string, using default character encoding
* UTF-8, use as default omit_xml_decl property false, use as default indent
* property false.
*
* @param doc
*        The input DOM
* @return the serialized document (as a String encoded using
*         default character encoding UTF-8)
* @throws XMLUtilsException
*         on errors
*/
public static String serializeDOM_S(Node doc) throws XMLUtilsException

/**
* Serialize a given DOM to an XML string, using a specified character
* encoding for the output XML string. If the specified encoding is not
* supported or is null, defaults on UTF-8. Use as default omit_xml_decl
* property false, use as default indent property falseIt.
*
* @param doc
*        The input DOM
* @param encoding
*        The desiderd character encoding for the output XML string
* @return the serialized document (as a String encoded using the
*         specified character encoding)
* @throws XMLUtilsException
*         on errors
*/
public static String serializeDOM_S(Node doc, String encoding) throws XMLUtilsException

/**
* Serialize a given DOM to a byte array containing an XML string, using
* default character encoding UTF-8.
*
* @param doc
*        The input DOM
* @return the serialized document (as a byte array)
* @throws XMLUtilsException
*         on errors
*/
public static byte[] serializeDOMToByteArray_S(Node doc) throws XMLUtilsException

/**
* Serialize a given DOM to a byte array containing an XML string, using a
* specified character encoding for the output XML buffer. If the specified
* encoding is not supported or is null, defaults on UTF-8.
*
* @param doc
*        The input DOM
* @param encoding
*        The desired character encoding for the output XML buffer
* @return the serialized document (as a byte array)
* @throws XMLUtilsException
*         on errors
*/
public static byte[] serializeDOMToByteArray_S(Document doc, String encoding) throws XMLUtilsException
  • XPath
/**
* Gets the node matching the XPath on the given node.
*
* @param theNode
*        The input DOM node.
* @param xPath
*        The XPath to evaluate.
* @return the node matching the XPath on the given node.
* @throws XMLUtilsException
*         when errors occurs.
*/
public static Node selectSingleNode_S(Node theNode, String xPath) throws XMLUtilsException

/**
* Gets the node matching the XPath on the given xml.
*
* @param xmlString
*        The input XML as string.
* @param xPath
*        The XPath to evaluate.
* @return the node matching the XPath on the given node.
* @throws XMLUtilsException
*         when errors occurs.
*/
public static Node selectSingleNode_S(String xmlString, String xPath) throws XMLUtilsException

/**
* Gets the list of nodes matching the XPath on the given node.
*
* @param theNode
*        The input DOM node.
* @param xPath
*        The XPath to evaluate.
* @return the list of nodes matching the XPath on the given node.
* @throws XMLUtilsException
*         when errors occurs.
*/
public static NodeList selectNodeList_S(Node theNode, String xPath) throws XMLUtilsException

/**
* Static helper method the get the string representation of the node
* content selected from XPath.
*
* @param theNode
*        The input DOM node.
* @param xPath
*        The XPath to evaluate.
* @param defaultValue
*        The value returned if XPath does not select any node.
* @return the string representation of the node content selected from
*         XPath.
* @throws XMLUtilsException
*         when errors occurs.
*
* @see #get(Node, String, String)
*/
public static String get_S(Node theNode, String xPath, String defaultValue) throws XMLUtilsException

/**
* Static helper method the get the string representation of the node
* content selected from XPath.
*
* @param theNode
*        The input DOM node.
* @param xPath
*        The XPath to evaluate.
* @return the string representation of the node content selected from
*         XPath.
* @throws XMLUtilsException
*         when errors occurs.
*
* @see #get(Node, String)
*/
public static String get_S(Node theNode, String xPath) throws XMLUtilsException
  • Utility
/**
* Replaces XML invalid chars within input String with the
* corresponding entities.
*
* @param input
*        the input String.
* @return the input string, with XML invalid chars replaced by the
*         corresponding entities.
*/
public static String replaceXMLInvalidChars(String input)

/**
* Replaces XML entities within input String with the corresponding
* invalid characters.
*
* @param input
*        the input String.
* @return the input string, with XML entities replaced by the corresponding
*         invalid chars.
*/
public static String replaceXMLEntities(String input)


Following the Class public instance methods

  • Parsing
  • Serialization
  • XPath
  • Document manipulation