Class XMLUtils
- Since:
- 4.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateSchema(Class<?> clazz) Create XML Schema (XSD) for JAXB class and return as XML string.static voidcreateSchema(Class<?> clazz, PrintStream printStream) Create XML Schema (XSD) for JAXB class and save into given print stream.getChildElements(Node node, String nodeName) Searches for all element children from a node having a specific node name.static ElementgetFirstChildElement(Node node) Searches for the first element child from a node - if existing.static DocumentgetXMLDocument(InputStream input) Parses a string into an XML document.static DocumentgetXMLDocument(String input) Parses a string into an XML document.static DocumentgetXMLDocument(InputSource input) Parses an input stream into an XML document.static <T> TobjectFromXML(byte[] bytes, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXML(Reader reader, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXML(String xmlstring, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXML(Source source, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXMLUnchecked(byte[] bytes, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXMLUnchecked(Reader reader, Class<T> T, Class<?>... types) Imports a data file (i.e.static <T> TobjectFromXMLUnchecked(String xmlstring, Class<T> T, Class<?>... types) Imports a data file (i.e.static StringobjectToUnformattedXML(Serializable serializable, Class<?>... types) Serialize an object into an unformatted XML string representationstatic StringWriterobjectToUnformattedXMLWriter(Serializable serializable, Class<?>... types) Serialize an object as unformatted XML into an string writerstatic StringobjectToXML(Serializable serializable, Class<?>... types) Serialize an object into an XML string representationstatic StringWriterobjectToXMLWriter(Serializable serializable, Class<?>... types) Serialize an object as XML into an string writerstatic voidvalidateXML(byte[] bytes) Validates a XML (i.e.static voidvalidateXML(InputStream input) Validates an XML (i.e.static booleanvalidateXML(InputStream xmlStream, InputStream... schemaStreams) Validate an XML input streamstatic voidTransform an XML Document given as a file reference into an output file using an XSL Document given as a file reference.static voidxslTransform(InputStream xmlStream, InputStream xslStream, Map<String, Object> args, Writer outputWriter) Transform an XML Document given as stream using an XSL Document given as another stream.
-
Method Details
-
getXMLDocument
Parses a string into an XML document. Returns the document or null, if anything fails.- Parameters:
input- XML String- Returns:
- new Document or NULL
- Since:
- 4.0.0
- See Also:
-
getXMLDocument
Parses an input stream into an XML document. Returns the document or null, if anything fails.- Parameters:
input- XML String- Returns:
- new Document or NULL
- Since:
- 4.0.0
-
getXMLDocument
Parses a string into an XML document. Returns the document or null, if anything fails.- Parameters:
input- XML String- Returns:
- new Document or NULL
- Since:
- 4.0.0
- See Also:
-
validateXML
Validate an XML input stream- Parameters:
xmlStream- the XML streamschemaStreams- e.g. stream of "/path/to/schema1.xsd"- Returns:
- true if input is a valid instance of XML schema
- Since:
- 4.0.0
-
objectFromXML
public static <T> T objectFromXML(Reader reader, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as a character reader) into an object.
If exceptions during unmarshalling or type casting occur, the method returns null.
This method might be deprecated in future versions of the SDK.
If exceptions should be handled on client side (which we recommend), useobjectFromXMLUnchecked(Reader, Class, Class...)instead.
- Parameters:
reader- readerT- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- (actually never thrown)- Since:
- 4.0.0
-
objectFromXMLUnchecked
public static <T> T objectFromXMLUnchecked(Reader reader, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as a character reader) into an object.
Any exception during unmarshalling or type casting is raised and must be handled on client side.
- Parameters:
reader-T- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.0.0
-
objectFromXML
public static <T> T objectFromXML(String xmlstring, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as a xml string) into an object.
If exceptions during unmarshalling or type casting occur, the method returns null.
This method might be deprecated in future versions of the SDK.
If exceptions should be handled on client side (which we recommend), useobjectFromXMLUnchecked(String, Class, Class...)instead.
- Parameters:
xmlstring- data file (XML String)T- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.0.0
-
objectFromXMLUnchecked
public static <T> T objectFromXMLUnchecked(String xmlstring, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as a xml string) into an object.
Any exception during unmarshalling or type casting is raised and must be handled on client side.
- Parameters:
xmlstring- xml String to be importedT- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.0.0
-
objectFromXML
public static <T> T objectFromXML(byte[] bytes, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as byte array) into an object.
Expects data to use default encoding of JVM. You may have to set "-dfile.encoding" of your JVM accordingly. PubServer expects all data in UTF-8.
If exceptions during unmarshalling or type casting occur, the method returns null.
This method might be deprecated in future versions of the SDK.
If exceptions should be handled on client side (which we recommend), useobjectFromXMLUnchecked(byte[], Class, Class...)instead.
- Parameters:
bytes- data file (byte array)T- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.0.0
-
objectFromXMLUnchecked
public static <T> T objectFromXMLUnchecked(byte[] bytes, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as byte array) into an object.
Expects data to use default encoding of JVM. You may have to set "-dfile.encoding" of your JVM accordingly. PubServer expects all data in UTF-8.
Any exception during unmarshalling or type casting is raised and must be handled on client side.
- Parameters:
bytes-T- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.0.0
-
objectFromXML
public static <T> T objectFromXML(Source source, Class<T> T, Class<?>... types) throws jakarta.xml.bind.JAXBException Imports a data file (i.e. as javax.xml.transform.Source) into an object.
Expects data to use default encoding of JVM. You may have to set "-dfile.encoding" of your JVM accordingly. PubServer expects all data in UTF-8.
Any exception during unmarshalling or type casting is raised and must be handled on client side.
- Parameters:
source- the xml sourceT- type to be returnedtypes- list of additional types for unmarshalling- Returns:
- new object of type T or null
- Throws:
jakarta.xml.bind.JAXBException- Since:
- 4.1.6
-
objectToXML
Serialize an object into an XML string representation- Parameters:
serializable- objecttypes- list of additional types for unmarshalling- Returns:
- XML string
- Since:
- 4.0.0
- See Also:
-
objectToUnformattedXML
Serialize an object into an unformatted XML string representation- Parameters:
serializable- objecttypes- list of additional types for unmarshalling- Returns:
- XML string
-
objectToXMLWriter
Serialize an object as XML into an string writer- Parameters:
serializable- objecttypes- list of additional types for unmarshalling- Returns:
- XML string
- Since:
- 4.0.0
-
objectToUnformattedXMLWriter
public static StringWriter objectToUnformattedXMLWriter(Serializable serializable, Class<?>... types) Serialize an object as unformatted XML into an string writer- Parameters:
serializable- objecttypes- list of additional types for unmarshalling- Returns:
- XML string
-
getFirstChildElement
Searches for the first element child from a node - if existing.- Parameters:
node- parent node- Returns:
- element child found or null.
- Throws:
NullArgumentException- if node is null.- Since:
- 4.0.0
-
getChildElements
Searches for all element children from a node having a specific node name.To retrieve all elements please use nodeName="*".
No support for namespaces. Only local name is compared.
- Parameters:
node- parent nodenodeName- name of the children nodes to be searched for- Returns:
- list of matching elements (never null).
- Throws:
NullArgumentException- if node is null.- Since:
- 4.1.0
-
xslTransform
public static void xslTransform(File xmlFile, File xslFile, File outFile, Map<String, Object> args) throws TransformerFactoryConfigurationError, TransformerException, IOExceptionTransform an XML Document given as a file reference into an output file using an XSL Document given as a file reference. You pipe a hashtable of string arguments into the transformation.- Parameters:
xmlFile-xslFile-outFile-args-- Throws:
TransformerFactoryConfigurationErrorTransformerExceptionIOException- Since:
- 4.0.0
- See Also:
-
xslTransform
public static void xslTransform(InputStream xmlStream, InputStream xslStream, Map<String, Object> args, Writer outputWriter) throws TransformerFactoryConfigurationError, TransformerExceptionTransform an XML Document given as stream using an XSL Document given as another stream. You pipe a hash table of string arguments into the transformation. Writes the result to aWriter- Parameters:
xmlStream-xslStream-args-outputWriter-- Throws:
TransformerFactoryConfigurationErrorTransformerException- Since:
- 4.0.0
-
validateXML
Validates a XML (i.e. as a array of bytes) using the JAXB XML parser, optionally matching against JAXB classes
- Parameters:
bytes- byte array to parse- Throws:
PubServerException
-
validateXML
Validates an XML (i.e. as a Reader) using the JAXB XML parser, optionally matching against JAXB classes
- Parameters:
input- reader to parse from- Throws:
PubServerException
-
createSchema
Create XML Schema (XSD) for JAXB class and return as XML string.- Parameters:
clazz- annotated with @XmlRootElement- Returns:
- Schema as XML string
- Throws:
PluginException- on any error
-
createSchema
Create XML Schema (XSD) for JAXB class and save into given print stream.- Parameters:
clazz- annotated with @XmlRootElementprintStream- target stream to write string data to- Throws:
PluginException- on any error
-