Package io.github.astrapi69.xml
Class XmlExtensions
- java.lang.Object
-
- io.github.astrapi69.xml.XmlExtensions
-
public final class XmlExtensions extends java.lang.Object
The classXmlExtensions
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.xml.sax.InputSource
getInputSource(java.lang.String xmlString)
Gets the input source from the given xml string.static <T> T
loadObject(java.io.File xmlFile)
Load from the given file name that should represent an xml file and transform it to the generic type object.static <T> T
loadObject(java.io.File xmlFile, java.lang.Class<T> clazz)
Load from the given file name that should represent an xml file and transform it to the generic type object.static <T> T
loadObject(java.lang.String xmlFileName)
Load from the given file name that should represent an xml file and transform it to the generic type object.static <T> T
loadObject(java.lang.String xmlFileName, java.lang.Class<T> clazz)
Load from the given file name that should represent an xml file and transform it to the generic type object.static java.lang.String
newTag(java.lang.String tagname, java.lang.String value, java.util.Map<java.lang.String,java.lang.String> attributes)
Creates a tag from the given string values.static java.lang.String
prettyPrint(java.lang.String xmlString)
Formats the given unformatted xmlString
object with default indent of 4static java.lang.String
prettyPrint(java.lang.String xmlString, int indent)
Formats the given unformatted xmlString
object with the given indent
-
-
-
Method Detail
-
getInputSource
public static org.xml.sax.InputSource getInputSource(java.lang.String xmlString)
Gets the input source from the given xml string.- Parameters:
xmlString
- the xml as string object- Returns:
- the input source
-
loadObject
public static <T> T loadObject(java.io.File xmlFile) throws java.io.IOException
Load from the given file name that should represent an xml file and transform it to the generic type object.- Type Parameters:
T
- the generic type- Parameters:
xmlFile
- the xml file- Returns:
- the object from the given xml file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
loadObject
public static <T> T loadObject(java.io.File xmlFile, java.lang.Class<T> clazz) throws java.io.IOException
Load from the given file name that should represent an xml file and transform it to the generic type object.- Type Parameters:
T
- the generic type- Parameters:
xmlFile
- the xml fileclazz
- the class of the generic type- Returns:
- the object from the given xml file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
prettyPrint
public static java.lang.String prettyPrint(java.lang.String xmlString) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXException, javax.xml.transform.TransformerException
Formats the given unformatted xmlString
object with default indent of 4- Parameters:
xmlString
- the given unformatted xmlString
object- Returns:
- the generated formatted xml
String
object - Throws:
javax.xml.parsers.ParserConfigurationException
- the parser configuration exceptionorg.xml.sax.SAXException
- is thrown if a sax parse error occursjava.io.IOException
- Signals that an I/O exception has occurredjavax.xml.transform.TransformerException
- is thrown if an error occurred with during the transformation process
-
prettyPrint
public static java.lang.String prettyPrint(java.lang.String xmlString, int indent) throws javax.xml.parsers.ParserConfigurationException, java.io.IOException, org.xml.sax.SAXException, javax.xml.transform.TransformerException
Formats the given unformatted xmlString
object with the given indent- Parameters:
xmlString
- the given unformatted xmlString
objectindent
- the number for indent the xmlString
object- Returns:
- the generated formatted xml
String
object - Throws:
javax.xml.parsers.ParserConfigurationException
- the parser configuration exceptionorg.xml.sax.SAXException
- is thrown if a sax parse error occursjava.io.IOException
- Signals that an I/O exception has occurredjavax.xml.transform.TransformerException
- is thrown if an error occurred with during the transformation process
-
loadObject
public static <T> T loadObject(java.lang.String xmlFileName) throws java.io.IOException
Load from the given file name that should represent an xml file and transform it to the generic type object.- Type Parameters:
T
- the generic type- Parameters:
xmlFileName
- the xml file name- Returns:
- the object from the given xml file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
loadObject
public static <T> T loadObject(java.lang.String xmlFileName, java.lang.Class<T> clazz) throws java.io.IOException
Load from the given file name that should represent an xml file and transform it to the generic type object.- Type Parameters:
T
- the generic type- Parameters:
xmlFileName
- the xml file nameclazz
- the class of the generic type- Returns:
- the object from the given xml file.
- Throws:
java.io.IOException
- Signals that an I/O exception has occurred.
-
newTag
public static java.lang.String newTag(java.lang.String tagname, java.lang.String value, java.util.Map<java.lang.String,java.lang.String> attributes)
Creates a tag from the given string values. Can be used for creating html or xml tags.- Parameters:
tagname
- the tag namevalue
- the value from the tagattributes
- a map with the attributes- Returns:
- the string
-
-