Class XMLUtil

java.lang.Object
com.landawn.abacus.util.XMLUtil

public final class XMLUtil extends Object
Since:
0.8
Author:
Haiyang Li
  • Method Details

    • marshal

      public static String marshal(Object jaxbBean)
      Marshaller.marshal(Object, java.io.Writer) is called
      Parameters:
      jaxbBean -
      Returns:
    • unmarshal

      public static <T> T unmarshal(Class<? extends T> cls, String xml)
      Unmarshaller#unmarshal(Object, java.io.Writer) is called
      Type Parameters:
      T -
      Parameters:
      cls -
      xml -
      Returns:
    • createMarshaller

      public static jakarta.xml.bind.Marshaller createMarshaller(String contextPath)
      Creates the marshaller.
      Parameters:
      contextPath -
      Returns:
    • createMarshaller

      public static jakarta.xml.bind.Marshaller createMarshaller(Class<?> cls)
      Creates the marshaller.
      Parameters:
      cls -
      Returns:
    • createUnmarshaller

      public static jakarta.xml.bind.Unmarshaller createUnmarshaller(String contextPath)
      Creates the unmarshaller.
      Parameters:
      contextPath -
      Returns:
    • createUnmarshaller

      public static jakarta.xml.bind.Unmarshaller createUnmarshaller(Class<?> cls)
      Creates the unmarshaller.
      Parameters:
      cls -
      Returns:
    • createDOMParser

      public static DocumentBuilder createDOMParser()
      DocumentBuilderFactory.newDocumentBuilder() is called. client should Cache the result for performance improvement if this method is called frequently.
      Returns:
    • createDOMParser

      public static DocumentBuilder createDOMParser(boolean ignoreComments, boolean ignoringElementContentWhitespace)
      Creates the DOM parser.
      Parameters:
      ignoreComments -
      ignoringElementContentWhitespace -
      Returns:
    • createContentParser

      public static DocumentBuilder createContentParser()
      Call recycleContentParser to reuse the instance.
      Returns:
    • recycleContentParser

      public static void recycleContentParser(DocumentBuilder docBuilder)
      Recycle content parser.
      Parameters:
      docBuilder -
    • createSAXParser

      public static SAXParser createSAXParser()
      Call recycleSAXParser to reuse the instance.
      Returns:
    • recycleSAXParser

      public static void recycleSAXParser(SAXParser saxParser)
      Recycle SAX parser.
      Parameters:
      saxParser -
    • createXMLStreamReader

      public static XMLStreamReader createXMLStreamReader(Reader reader)
      Parameters:
      reader -
      Returns:
    • createXMLStreamReader

      public static XMLStreamReader createXMLStreamReader(InputStream stream)
      Parameters:
      stream -
      Returns:
    • createXMLStreamReader

      public static XMLStreamReader createXMLStreamReader(InputStream stream, String encoding)
      Parameters:
      stream -
      encoding -
      Returns:
    • createFilteredStreamReader

      public static XMLStreamReader createFilteredStreamReader(XMLStreamReader reader, StreamFilter filter)
      Creates the filtered stream reader.
      Parameters:
      reader -
      filter -
      Returns:
    • createXMLStreamWriter

      public static XMLStreamWriter createXMLStreamWriter(Writer writer)
      Parameters:
      writer -
      Returns:
    • createXMLStreamWriter

      public static XMLStreamWriter createXMLStreamWriter(OutputStream stream)
      Parameters:
      stream -
      Returns:
    • createXMLStreamWriter

      public static XMLStreamWriter createXMLStreamWriter(OutputStream stream, String encoding)
      Parameters:
      stream -
      encoding -
      Returns:
    • createXMLTransformer

      public static Transformer createXMLTransformer()
      Returns:
    • transform

      public static void transform(Document doc, File xmlFile)
      Parameters:
      doc -
      xmlFile -
    • transform

      public static void transform(Document doc, OutputStream ou)
      Parameters:
      doc -
      ou -
    • xmlEncode

      public static String xmlEncode(Object bean)
      Parameters:
      bean -
      Returns:
    • xmlDecode

      public static <T> T xmlDecode(String xml)
      Type Parameters:
      T -
      Parameters:
      xml -
      Returns:
    • getElementsByTagName

      public static List<Element> getElementsByTagName(Element node, String tagName)
      Gets the elements by tag name.
      Parameters:
      node -
      tagName -
      Returns:
    • getNodesByName

      public static List<Node> getNodesByName(Node node, String nodeName)
      Gets the nodes by name.
      Parameters:
      node -
      nodeName -
      Returns:
    • getNextNodeByName

      public static Node getNextNodeByName(Node node, String nodeName)
      Gets the next node by name.
      Parameters:
      node -
      nodeName -
      Returns:
    • readAttributes

      public static Map<String,String> readAttributes(Node node)
      Parameters:
      node -
      Returns:
    • getAttribute

      public static String getAttribute(Node node, String attrName)
      Gets the attribute.
      Parameters:
      node -
      attrName -
      Returns:
    • isTextElement

      public static boolean isTextElement(Node node)
      Parameters:
      node -
      Returns:
      boolean
    • getTextContent

      public static String getTextContent(Node node)
      Gets the text content.
      Parameters:
      node -
      Returns:
    • getTextContent

      public static String getTextContent(Node node, boolean ignoreWhiteChar)
      Gets the text content.
      Parameters:
      node -
      ignoreWhiteChar -
      Returns:
    • writeCharacters

      public static void writeCharacters(StringBuilder sb, char[] cbuf) throws IOException
      Parameters:
      sb -
      cbuf -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(StringBuilder sb, char[] cbuf, int off, int len) throws IOException
      Parameters:
      sb -
      cbuf -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(StringBuilder sb, String str) throws IOException
      Parameters:
      sb -
      str -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(StringBuilder sb, String str, int off, int len) throws IOException
      Parameters:
      sb -
      str -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(OutputStream os, char[] cbuf) throws IOException
      Parameters:
      os -
      cbuf -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(OutputStream os, char[] cbuf, int off, int len) throws IOException
      Parameters:
      os -
      cbuf -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(OutputStream os, String str) throws IOException
      Parameters:
      os -
      str -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(OutputStream os, String str, int off, int len) throws IOException
      Parameters:
      os -
      str -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(Writer writer, char[] cbuf) throws IOException
      Parameters:
      writer -
      cbuf -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(Writer writer, char[] cbuf, int off, int len) throws IOException
      Parameters:
      writer -
      cbuf -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(Writer writer, String str) throws IOException
      Parameters:
      writer -
      str -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • writeCharacters

      public static void writeCharacters(Writer writer, String str, int off, int len) throws IOException
      Parameters:
      writer -
      str -
      off -
      len -
      Throws:
      IOException - Signals that an I/O exception has occurred.