Interface XmlTools

All Known Implementing Classes:
SaxTools

@API(status=STABLE, since="1.0", consumers="SaxTools") @Component public interface XmlTools
XML Tools are based on the event driven SAX concept. SAX = Simple API for XML
The implementation offers all necessary functions to deal with XML inside Java Applications.
Since:
1.0
Version:
1.2
Author:
elmar.dott@gmail.com
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Identifier for the given feature.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Check if a external schema file s configured.
    boolean
    Validate well formed XML content (XML 1.0) against a given grammar.
    boolean
    Check XML content (XML 1.0) if is well formed.
    parseXmlFile(File xmlFile)
    Parse a given XML File to grab the content.
    Parse a given XML String to grab the content.
    Before writeing a XML Document on a file, especially computer generated XML Content, the content should formatted by a CodeBeautifier.
    void
    Reset the external schema file to NULL.
    void
    Set explicit the schema file for the validation option.
    Shrink the XML content to reduce the file size for a higher performance in automated processing.
    transformXslt(File xml, File xslt)
    Transform an XML File by a given XSLT to a new Output.
    void
    writeXmlToFile(String content, String destinationFile)
    Writes a XML String into a new file.
  • Field Details

    • FEATURE_ID

      @API(status=STABLE, since="1.2") static final String FEATURE_ID
      Identifier for the given feature.
      See Also:
  • Method Details

    • parseXmlFile

      @API(status=STABLE, since="1.0") String parseXmlFile(File xmlFile)
      Parse a given XML File to grab the content.
      Parameters:
      xmlFile - as File
      Returns:
      content as String
    • parseXmlString

      @API(status=STABLE, since="1.1") String parseXmlString(String xml)
      Parse a given XML String to grab the content.
      Parameters:
      xml - as String
      Returns:
      content as String
    • prettyPrintXml

      @API(status=STABLE, since="1.0") String prettyPrintXml()
      Before writeing a XML Document on a file, especially computer generated XML Content, the content should formatted by a CodeBeautifier. This function Beautifies the XML Sources with the following rules:
    • set content to UTF-8 without BOM (Byte Order Mark)
    • automated line breaks and indents
    • remove trailing space
    • replace TAB with 4 space characters
    • Returns:
      content as String
    • shrinkContent

      @API(status=STABLE, since="1.1") String shrinkContent(String content)
      Shrink the XML content to reduce the file size for a higher performance in automated processing. The following option will be executed:
    • remove XML comments
    • remove whitespace
    • remove linebreak
    • The final result is an XML in one row without comments and whitespace in one line. input and output is not parsed or checked for well formed.
      Parameters:
      content - as String
      Returns:
      shrink content as String
    • transformXslt

      @API(status=STABLE, since="1.1") String transformXslt(File xml, File xslt)
      Transform an XML File by a given XSLT to a new Output.
      Parameters:
      xml - as File
      xslt - as File
      Returns:
      transformation as String
    • hasExternalSchemaFile

      @API(status=STABLE, since="1.1") boolean hasExternalSchemaFile()
      Check if a external schema file s configured.
      Returns:
      true on success
    • isValid

      @API(status=STABLE, since="1.0") boolean isValid()
      Validate well formed XML content (XML 1.0) against a given grammar. Grammar files can be DTD or XML Schema. THe validation contains also a well formed test for the XML file.
      Returns:
      true on success
    • isWellFormed

      @API(status=STABLE, since="1.0") boolean isWellFormed()
      Check XML content (XML 1.0) if is well formed. the well formed rules for XML are defined as:
    • the structure of a XML document is a tree and each node is defined as TAG
    • each document contains exact one root tag
    • element tags are case-sensitive
    • content be delimited with a beginning and end tag
    • begin, end, and empty-element tags that delimit the elements are correctly nested, with none missing and none overlapping Detail
    • it contains only properly encoded legal Unicode characters
    • special characters like: > < & have to be encoded (StringUtils.escapeXmlCharacters()) Information: https://en.wikipedia.org/wiki/Well-formed_document
    • Returns:
      true on success
    • resetExternalSchema

      @API(status=STABLE, since="1.1") void resetExternalSchema()
      Reset the external schema file to NULL.
    • setSchemaFile

      @API(status=STABLE, since="1.0") void setSchemaFile(File schema)
      Set explicit the schema file for the validation option. This method overwrites in the XML document declares Schemata.
      Parameters:
      schema - as File
    • writeXmlToFile

      @API(status=STABLE, since="1.0") void writeXmlToFile(String content, String destinationFile) throws IOException
      Writes a XML String into a new file.
      Parameters:
      content - as string
      destinationFile - as String
      Throws:
      IOException