Package org.europa.together.business
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.
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 -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck if a external schema file s configured.booleanisValid()Validate well formed XML content (XML 1.0) against a given grammar.booleanCheck 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_documentparseXmlFile(File xmlFile) Parse a given XML File to grab the content.parseXmlString(String xml) 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.voidReset the external schema file to NULL.voidsetSchemaFile(File schema) Set explicit the schema file for the validation option.shrinkContent(String content) 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.voidwriteXmlToFile(String content, String destinationFile) Writes a XML String into a new file.
-
Field Details
-
FEATURE_ID
Identifier for the given feature.- See Also:
-
-
Method Details
-
parseXmlFile
Parse a given XML File to grab the content.- Parameters:
xmlFile- as File- Returns:
- content as String
-
parseXmlString
Parse a given XML String to grab the content.- Parameters:
xml- as String- Returns:
- content as 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
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
Transform an XML File by a given XSLT to a new Output.- Parameters:
xml- as Filexslt- 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
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 stringdestinationFile- as String- Throws:
IOException
-