Package es.gob.afirma.mreport.utils
Class XMLUtils
- java.lang.Object
-
- es.gob.afirma.mreport.utils.XMLUtils
-
public final class XMLUtils extends java.lang.ObjectClass contains utilities for processing XML.
Project:Horizontal platform to generation signature reports in legible format.
- Version:
- 1.2, 16/09/2023.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.DocumentgetBlankDocument()Creates a black document.static org.w3c.dom.DocumentgetDocument(byte[] xml)Gets Document interface that represents the entire HTML or XML document.static org.w3c.dom.DocumentgetDocument(java.io.InputStream in)Gets Document interface that represents the entire HTML or XML document.static org.w3c.dom.NodeListgetNodes(org.w3c.dom.Node xml, java.lang.String xpath)Get the list of nodes that meet the XPath condition provided.static java.lang.StringgetNodeValue(org.w3c.dom.Node xml, java.lang.String xpath)Get the value of node located in the XPath supplied.static byte[]getXMLBytes(org.w3c.dom.Node xml)Gets a XML as bytes array.static voidincludeElementValue(org.w3c.dom.Document xml, java.lang.String xpath, java.lang.Object value, int type)Method that includes a DOM object into the XML supplied and in the indicated path.static voidremoveNodes(org.w3c.dom.Document xml, java.util.ArrayList<java.lang.String> nodesToRemove)This method removes of the XML supplied the nodes indicated.static byte[]xslTransform(byte[] xml, byte[] xslt)Method that returns the XML result of applying the XSL transformation to the data supplied.
-
-
-
Method Detail
-
getBlankDocument
public static org.w3c.dom.Document getBlankDocument() throws UtilsExceptionCreates a black document.- Returns:
- A empty DOM document.
- Throws:
UtilsException- If an error occurs.
-
xslTransform
public static byte[] xslTransform(byte[] xml, byte[] xslt) throws UtilsExceptionMethod that returns the XML result of applying the XSL transformation to the data supplied.- Parameters:
xml- XML input.xslt- XSL Transform.- Returns:
- the XML result of applying the XSL transformation
- Throws:
UtilsException- There was an error processing the XML.
-
getXMLBytes
public static byte[] getXMLBytes(org.w3c.dom.Node xml) throws UtilsExceptionGets a XML as bytes array.- Parameters:
xml- XML document.- Returns:
- XML as bytes array.
- Throws:
UtilsException- There was an error processing the XML.
-
getNodes
public static org.w3c.dom.NodeList getNodes(org.w3c.dom.Node xml, java.lang.String xpath) throws UtilsExceptionGet the list of nodes that meet the XPath condition provided.- Parameters:
xml- Node where to search.xpath- XPath location of node to get.- Returns:
- List of nodes located in XPath supplied.
- Throws:
UtilsException- There was an error processing the XML.
-
getNodeValue
public static java.lang.String getNodeValue(org.w3c.dom.Node xml, java.lang.String xpath) throws UtilsExceptionGet the value of node located in the XPath supplied.- Parameters:
xml- Node where to search.xpath- XPath location of node that planning to obtain the value.- Returns:
- Node value. Null if the node is not found.
- Throws:
UtilsException- There was an error processing the XML.
-
getDocument
public static org.w3c.dom.Document getDocument(java.io.InputStream in) throws UtilsExceptionGets Document interface that represents the entire HTML or XML document.- Parameters:
in- InputStream containing the content to be parsed.- Returns:
- Document Result of parsing the InputStream.
- Throws:
UtilsException- There was an error processing the XML.
-
getDocument
public static org.w3c.dom.Document getDocument(byte[] xml) throws UtilsExceptionGets Document interface that represents the entire HTML or XML document.- Parameters:
xml- Array of bytes that contain the content to be parsed.- Returns:
- Document result of parsing the bytes.
- Throws:
UtilsException- There was an error processing the XML.
-
includeElementValue
public static void includeElementValue(org.w3c.dom.Document xml, java.lang.String xpath, java.lang.Object value, int type) throws UtilsExceptionMethod that includes a DOM object into the XML supplied and in the indicated path.- Parameters:
xml- Document for including of element.xpath- Xpath that locates the node where will be included the element.value- Object that represents the element to be included. Allowed Object:
String- If the object to include is a text node or a cdata section.
Node- If the object to include is a element node.type- Parameter that indicates the type object to be included. Allowed values:
Node.TEXT_NODE- If the object to include is a text node.
Node.CDATA_SECTION_NODE- If the object to include is a cdata section.
Node.ELEMENT_NODE- If the object to include is a element node.- Throws:
UtilsException- There was an error processing the XML.
-
removeNodes
public static void removeNodes(org.w3c.dom.Document xml, java.util.ArrayList<java.lang.String> nodesToRemove) throws UtilsExceptionThis method removes of the XML supplied the nodes indicated.- Parameters:
xml- Document for removing the nodes supplied.nodesToRemove- List of XPath that locate the nodes to remove.- Throws:
UtilsException- There was an error processing the XML.
-
-