Class JKXmlHandler

java.lang.Object
com.jk.core.xml.JKXmlHandler

public class JKXmlHandler extends Object
This class is a utility class used for handling XML parsing and marshaling using JAXB (Java Architecture for XML Binding).
Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • JKXmlHandler

      public JKXmlHandler()
  • Method Details

    • getInstance

      public static JKXmlHandler getInstance()
      This method gets the singleton instance of the JKXmlHandler.
      Returns:
      the singleton instance of the JKXmlHandler.
    • parse

      public <T> T parse(InputStream in, Class<?>... clas)
      This method parses XML data from an InputStream into Java objects.
      Type Parameters:
      T - Specifies the type of deserialized object.
      Parameters:
      in - Specifies the InputStream containing the XML data.
      clas - Specifies the root element classes for unmarshaling.
      Returns:
      the deserialized Java object.
    • toXml

      public void toXml(Object object, OutputStream out, Class<?>... clas)
      This method serializes a Java object into XML and writes it to an OutputStream.
      Parameters:
      object - Specifies the Java object to be serialized.
      out - Specifies the OutputStream to write the XML data to.
      clas - Specifies the root element classes for marshaling.
    • toXml

      public String toXml(Object obj)
      This method serializes a Java object into XML format and returns it as a string.
      Parameters:
      obj - Specifies the Java object to be serialized.
      Returns:
      the XML representation of the object as a string.
    • toXml

      public String toXml(Object obj, Class<?>... clas)
      This method serializes a Java object into XML format and returns it as a string.
      Parameters:
      obj - Specifies the Java object to be serialized.
      clas - Specifies the root element classes for marshaling.
      Returns:
      the XML representation of the object as a string.