Class XmlUtils
java.lang.Object
org.openehealth.ipf.commons.xml.XmlUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringMarshals a JAXB object into its XML string representation, without XML declaration.static byte[]Marshals a DOM node into indented XML bytes, without XML declaration.static StringrenderJaxb(jakarta.xml.bind.JAXBContext jaxbContext, Object object, Boolean prettyPrint) Deprecated, for removal: This API element is subject to removal in a future version.static StringReturns local name of the root element of the XML document represented by the given string, ornull, when the given string does not contain valid XML.static byte[]Deprecated, for removal: This API element is subject to removal in a future version.usemarshal(Node)static SourceCreates an XML Source from the given XML String.static ObjectUnmarshals an untrusted XML string with JAXB.static <T> TUnmarshals an untrusted XML string with JAXB into an object of the given type, seeunmarshal(JAXBContext, String).
-
Method Details
-
source
-
rootElementName
Returns local name of the root element of the XML document represented by the given string, ornull, when the given string does not contain valid XML.- Parameters:
s- XML string.- Returns:
- root element local name, or
nullwhen it could not be determined.
-
marshal
public static String marshal(jakarta.xml.bind.JAXBContext jaxbContext, Object object, boolean prettyPrint) Marshals a JAXB object into its XML string representation, without XML declaration.- Parameters:
jaxbContext- JAXB context corresponding to the object's typeobject- the JAXB object to be marshalledprettyPrint- whether the XML shall be pretty printed- Returns:
- XML string representation of the given JAXB object
- Throws:
RuntimeException- wrapping theJAXBExceptionif marshalling fails- Since:
- 6.1
-
marshal
Marshals a DOM node into indented XML bytes, without XML declaration.- Parameters:
node- DOM node to marshal- Returns:
- XML bytes
- Throws:
TransformerException- if serialization fails- Since:
- 6.1
-
unmarshal
public static Object unmarshal(jakarta.xml.bind.JAXBContext jaxbContext, String xml) throws jakarta.xml.bind.JAXBException Unmarshals an untrusted XML string with JAXB. The document is parsed by a reader fromXmlSecurity.newXmlReader(), so anyDOCTYPEdeclaration is rejected.- Parameters:
jaxbContext- JAXB context corresponding to the expected contentxml- XML string- Returns:
- the unmarshalled object, which may be a
JAXBElementfor types without root element declaration - Throws:
jakarta.xml.bind.JAXBException- if the document cannot be parsed or unmarshalled, including when it contains aDOCTYPEdeclaration- Since:
- 6.1
-
unmarshal
public static <T> T unmarshal(jakarta.xml.bind.JAXBContext jaxbContext, String xml, Class<T> type) throws jakarta.xml.bind.JAXBException Unmarshals an untrusted XML string with JAXB into an object of the given type, seeunmarshal(JAXBContext, String).- Type Parameters:
T- expected type of the unmarshalled object- Parameters:
jaxbContext- JAXB context corresponding to the expected contentxml- XML stringtype- expected type of the unmarshalled object- Returns:
- the unmarshalled object
- Throws:
jakarta.xml.bind.JAXBException- if the document cannot be parsed or unmarshalledClassCastException- if the unmarshalled object is not of the expected type- Since:
- 6.1
-
renderJaxb
@Deprecated(since="6.1", forRemoval=true) public static String renderJaxb(jakarta.xml.bind.JAXBContext jaxbContext, Object object, Boolean prettyPrint) Deprecated, for removal: This API element is subject to removal in a future version. -
serialize
@Deprecated(since="6.1", forRemoval=true) public static byte[] serialize(Node inputNode) throws Exception Deprecated, for removal: This API element is subject to removal in a future version.usemarshal(Node)- Throws:
Exception
-
marshal(JAXBContext, Object, boolean)