public final class UtilsXML
extends java.lang.Object
Class that contains methods related to the manage of XML elements.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
| Modifier and Type | Method and Description |
|---|---|
static org.w3c.dom.Element |
createChild(org.w3c.dom.Element e,
java.lang.String childName)
Method that creates a child element from a parent element.
|
static org.w3c.dom.Element |
createElementValue(org.w3c.dom.Element e,
java.lang.String elementName,
java.lang.String elementValue)
Method that creates a new element as a child of a parent element.
|
static void |
deleteNodesNotUsed(org.w3c.dom.Element xmlNode,
java.lang.String[] optionalNodeTypes)
Method that removes all the nodes and tags not used from a parent XML element.
|
static boolean |
existsElement(org.w3c.dom.Element e,
java.lang.String elementName)
Method that checks if a element exists from a parent element.
|
static java.lang.String |
getAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName)
Method that obtains the value of an attribute of a XML element.
|
static java.lang.String |
getAttributeValue(org.w3c.dom.Element element,
java.lang.String elementPath,
java.lang.String attributeName)
Method that obtains the value of an attribute of a XML element.
|
static org.w3c.dom.Element |
getChildElement(org.w3c.dom.Element parentElement,
java.lang.String childElementName,
java.lang.String signatureId,
boolean isRequired)
Method that obtains certain element as a child of a parent element.
|
static java.util.List<org.w3c.dom.Element> |
getChildElements(org.w3c.dom.Element parentElement,
java.lang.String childElementName)
Method that obtains certain elements as childs of a parent element.
|
static org.w3c.dom.NodeList |
getChildNodesByLocalNames(org.w3c.dom.Node element,
java.lang.String path)
Method that obtains a list with the child elements localized in certain
local-name path for certain root element. |
static org.w3c.dom.Document |
getDocument(java.io.InputStream is)
Method that obtains a
Document object from an input stream. |
static org.w3c.dom.Document |
getDocumentWithXsdValidation(java.io.File xsdSchema,
java.io.InputStream xml)
Method that obtains a
Document object from an input stream and validates XML document against an XSD schema. |
static org.w3c.dom.Element |
getElement(org.w3c.dom.Element element,
java.lang.String elementName)
Method that obtains the child element from a parent element.
|
static java.lang.String |
getElementValue(org.w3c.dom.Element e)
Method that obtains the value of a XML element.
|
static java.lang.String |
getElementValue(org.w3c.dom.Element e,
java.lang.String elementName)
Method that obtains the value of a child element from a parent element.
|
static org.w3c.dom.Element |
getFirstElementNode(org.w3c.dom.Element element)
Method that obtains the first child XML element from a parent element.
|
static java.lang.String |
getNodeXPath(org.w3c.dom.Node node)
Method that obtains the absolute path of a node.
|
static java.lang.String |
getRelativeXPath(org.w3c.dom.Node nodeChild,
org.w3c.dom.Node parent)
Method that obtains the relative path of a child node from a parent node.
|
static org.w3c.dom.Element |
insertAttributeValue(org.w3c.dom.Element xmlNode,
java.lang.String attributePath,
java.lang.String value)
Method that adds an attribute to certain node.
|
static org.w3c.dom.Element |
insertValueElement(org.w3c.dom.Element element,
java.lang.String elementName,
java.lang.String value)
Method that inserts a element as a child into a XML element.
|
static org.w3c.dom.Document |
newDocument()
Method that instancies a new
Document object. |
static org.w3c.dom.Document |
parseDocument(java.io.Reader input)
Method that obtains a XML document from an input stream.
|
static org.w3c.dom.Document |
parseXMLDocument(java.lang.String xml)
Parse a XML Document to a
Document instance. |
static void |
removeAfirmaAttribute(org.w3c.dom.Element element)
Method that removes the all
afirmaNodeType nodes from a parent XML element. |
static org.w3c.dom.Element |
removeElement(org.w3c.dom.Element e,
java.lang.String elementName)
Method that deletes a child element from a parent element.
|
static org.w3c.dom.Element |
replaceElementValue(org.w3c.dom.Element e,
java.lang.String elementName,
java.lang.String elementValue)
Method that replaces an element with a new value.
|
static org.w3c.dom.Element |
searchChild(org.w3c.dom.Element e,
java.lang.String childName)
Method that searches a child element from a parent element.
|
static java.util.List<org.w3c.dom.Element> |
searchChildElements(org.w3c.dom.Element e)
Method that obtains a list with the child elements from a parent element.
|
static java.util.List<java.lang.Object> |
searchListChilds(org.w3c.dom.Element e,
java.lang.String childElementName)
Method that obtains a list with the child elements localized on the first level of the hierarchical child structure from a parent element.
|
static java.lang.String |
toXMLString(java.lang.Object xmlElement,
java.lang.String rootName,
boolean asAttributes)
Method that obtains a string with the values of a XML element.
|
static java.lang.String |
transformDOMtoString(org.w3c.dom.Document doc)
Method that generates a string with XML format from a XML document.
|
static java.lang.String |
transformDOMtoString(org.w3c.dom.Element xmlElement,
boolean omitXmlDeclaration)
Method that generates a string with XML format from a DOM tree structure.
|
public static org.w3c.dom.Document parseDocument(java.io.Reader input)
throws TransformersException
input - Parameter that represents the input stream.TransformersException - If the method fails.public static java.lang.String getElementValue(org.w3c.dom.Element e)
e - Parameter that represents the XML element.null if the XML element hasn't any value.public static java.lang.String getElementValue(org.w3c.dom.Element e,
java.lang.String elementName)
e - Parameter that represents the parent element.elementName - Parameter that represents the name of the child element.null if the element hasn't any value or the child element doesn't exist.public static org.w3c.dom.Element getElement(org.w3c.dom.Element element,
java.lang.String elementName)
element - Parameter that represents the parent element.elementName - Parameter that represents the name of the child element.null if the child element doesn't exist.public static org.w3c.dom.Element searchChild(org.w3c.dom.Element e,
java.lang.String childName)
e - Parameter that represents the parent element.childName - Parameter that represents the name of the child element to find.null if the child element doesn't exist.public static java.util.List<java.lang.Object> searchListChilds(org.w3c.dom.Element e,
java.lang.String childElementName)
e - Parameter that represents the parent element.childElementName - Parameter that represents the name of the child elements to find.public static java.util.List<org.w3c.dom.Element> searchChildElements(org.w3c.dom.Element e)
e - Parameter that represents the parent element.public static org.w3c.dom.Element createChild(org.w3c.dom.Element e,
java.lang.String childName)
e - Parameter that represents the parent element.childName - Parameter that represents the name of the element to create.public static boolean existsElement(org.w3c.dom.Element e,
java.lang.String elementName)
e - Parameter that represents the parent element.elementName - Parameter that represents the name of the element to check.public static org.w3c.dom.Element removeElement(org.w3c.dom.Element e,
java.lang.String elementName)
e - Parameter that represents the parent element.elementName - Parameter that represents the name of the element to remove.null if the element cannot be removed.public static org.w3c.dom.Element replaceElementValue(org.w3c.dom.Element e,
java.lang.String elementName,
java.lang.String elementValue)
e - Parameter that represents the parent element.elementName - Parameter that represents the name of the element to replace.elementValue - Parameter that represents the new value of the element.public static org.w3c.dom.Element createElementValue(org.w3c.dom.Element e,
java.lang.String elementName,
java.lang.String elementValue)
e - Parameter that represents the parent element.elementName - Parameter that represents the name of the element to create.elementValue - Parameter that represents the value of the element to create.public static java.lang.String toXMLString(java.lang.Object xmlElement,
java.lang.String rootName,
boolean asAttributes)
throws TransformersException
xmlElement - Parameter that represents the XML element.rootName - Parameter that represents the name of the root element. It cannot be null.asAttributes - Parameter that indicates if the values of the XML element must be defined as attributes (true) or as elements (false).TransformersException - If the method fails.public static java.lang.String transformDOMtoString(org.w3c.dom.Element xmlElement,
boolean omitXmlDeclaration)
throws TransformersException
xmlElement - Parameter that represents the XML element to process.omitXmlDeclaration - Parameter that specifies whether the XSLT processor should output an XML declaration (true) or not (false).TransformersException - If the method fails.public static java.lang.String transformDOMtoString(org.w3c.dom.Document doc)
throws TransformersException
doc - Parameter that represents the XML document.TransformersException - If the method fails.public static void deleteNodesNotUsed(org.w3c.dom.Element xmlNode,
java.lang.String[] optionalNodeTypes)
afirmaNodeType nodes and deletes them
whether the type is equal than one of the indicated types.xmlNode - Parameter that represents the parent XML element.optionalNodeTypes - Parameter that represents the array with the types of the nodes to remove.public static void removeAfirmaAttribute(org.w3c.dom.Element element)
afirmaNodeType nodes from a parent XML element.element - Parameter that represents the parent XML element.public static org.w3c.dom.Element insertAttributeValue(org.w3c.dom.Element xmlNode,
java.lang.String attributePath,
java.lang.String value)
xmlNode - Parameter that represents the node.attributePath - Parameter that represents the path of the attribute name.value - Parameter that represents the value of the attribute.public static org.w3c.dom.Element insertValueElement(org.w3c.dom.Element element,
java.lang.String elementName,
java.lang.String value)
element - Parameter that represents the parent XML element.elementName - Parameter that represents the name of the element to insert.value - Parameter that represents the value of the element to insert.public static java.lang.String getAttributeValue(org.w3c.dom.Element element,
java.lang.String elementPath,
java.lang.String attributeName)
element - Parameter that represents the parent XML element.elementPath - Parameter that represents the XPath path of the element to find.attributeName - Parameter that represents the name of the attribute to find.public static java.lang.String getAttributeValue(org.w3c.dom.Element element,
java.lang.String attributeName)
element - Parameter that represents the parent XML element.attributeName - Parameter that represents the name of the attribute to find.public static java.lang.String getRelativeXPath(org.w3c.dom.Node nodeChild,
org.w3c.dom.Node parent)
nodeChild - Parameter that represents the child node.parent - Parameter that represents the parent node.public static java.lang.String getNodeXPath(org.w3c.dom.Node node)
node - Parameter that represents the node.public static org.w3c.dom.Element getFirstElementNode(org.w3c.dom.Element element)
element - Parameter that represents the parent element.public static org.w3c.dom.Document getDocument(java.io.InputStream is)
throws javax.xml.transform.TransformerException
Document object from an input stream.is - Parameter that represents the input stream.Document object associated.javax.xml.transform.TransformerException - If the method fails.public static org.w3c.dom.Document newDocument()
throws javax.xml.parsers.ParserConfigurationException
Document object.Document object.javax.xml.parsers.ParserConfigurationException - If the method fails.public static org.w3c.dom.Document getDocumentWithXsdValidation(java.io.File xsdSchema,
java.io.InputStream xml)
throws TransformersException
Document object from an input stream and validates XML document against an XSD schema.xsdSchema - xsd schema definition.xml - xml to convert.Document object.TransformersException - If the process fails.public static org.w3c.dom.Document parseXMLDocument(java.lang.String xml)
Document instance.xml - string with XML content.document instance if the string given is a XML document or null otherwise.public static org.w3c.dom.Element getChildElement(org.w3c.dom.Element parentElement,
java.lang.String childElementName,
java.lang.String signatureId,
boolean isRequired)
throws SigningException
parentElement - Parameter that represents the parent element.childElementName - Parameter that represents the name of the element to find.signatureId - Parameter that represents the Id attribute of the signature.isRequired - Parameter that indicates whether the elements is required (true) or not (false).null.SigningExceptionpublic static java.util.List<org.w3c.dom.Element> getChildElements(org.w3c.dom.Element parentElement,
java.lang.String childElementName)
parentElement - Parameter that represents the parent element.childElementName - Parameter that represents the name of the element to find.public static org.w3c.dom.NodeList getChildNodesByLocalNames(org.w3c.dom.Node element,
java.lang.String path)
throws javax.xml.xpath.XPathExpressionException
local-name path for certain root element.element - Parameter that represents the root element.path - Parameter that represents the path.local-name path for the root element.javax.xml.xpath.XPathExpressionException - If some expression cannot be evaluated