Package es.uji.crypto.xades.jxades.util
Class XMLUtils
- java.lang.Object
-
- es.uji.crypto.xades.jxades.util.XMLUtils
-
public final class XMLUtils extends java.lang.Object
Common XML Tasks
-
-
Field Summary
Fields Modifier and Type Field Description private static java.nio.charset.Charset
charset
-
Constructor Summary
Constructors Constructor Description XMLUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.w3c.dom.Element
createLastPathComponent(org.w3c.dom.Document doc, java.lang.String[] path)
Creates (only if necessary) and returns the element which is at the end of the specified path.static java.lang.String
getAttributeByName(org.w3c.dom.Node node, java.lang.String name)
Get the attribute with given name's valuestatic org.w3c.dom.Element
getChildElementByChain(org.w3c.dom.Element element, java.lang.String[] chain, boolean create)
Returns the element which is at the end of the specified chain... static org.w3c.dom.Element
getChildElementByTagName(org.w3c.dom.Element parent, java.lang.String tagName)
Returns the child element with the specified tagName for the specified parent elementstatic org.w3c.dom.Element
getChildElementByTagNameNS(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String nsName)
static java.util.List<org.w3c.dom.Element>
getChildElementsByTagName(org.w3c.dom.Element parent, java.lang.String tagName)
static java.util.List<org.w3c.dom.Element>
getChildElementsByTagNameNS(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String nsName)
private static org.w3c.dom.Node
getChildNodeByType(org.w3c.dom.Element element, short nodeType)
static org.w3c.dom.CDATASection
getElementCDataNode(org.w3c.dom.Element element)
Returns element's CDATA Nodestatic java.lang.String
getElementCDataValue(org.w3c.dom.Element e)
Gets CDATA value of an elementstatic org.w3c.dom.Text
getElementTextNode(org.w3c.dom.Element element)
Returns element's TEXT Nodestatic java.lang.String
getElementTextValueDeprecated(org.w3c.dom.Element parentNode)
Get the data of the element , no matter whether it is TXT ot CDATAstatic void
printChildElements(org.w3c.dom.Element parent, java.io.PrintStream out, boolean deep, java.lang.String prefix)
Used for debugingstatic void
setElementCDataValue(org.w3c.dom.Element e, java.lang.String data)
Sets element CDATA datastatic void
setElementTextValue(org.w3c.dom.Element e, java.lang.String data)
Sets element TEXT datastatic void
writeXML(java.io.File file, org.w3c.dom.Node node)
static void
writeXML(java.io.OutputStream outStream, org.w3c.dom.Node node)
static void
writeXML(java.io.OutputStream outStream, org.w3c.dom.Node node, boolean indent)
static void
writeXML(java.io.Writer writer, org.w3c.dom.Document document, java.lang.String doctypeSystem, java.lang.String doctypePublic)
static void
writeXML(java.io.Writer writer, org.w3c.dom.Node node, boolean indent)
Writes the specified document to the given file.
-
-
-
Method Detail
-
getAttributeByName
public static java.lang.String getAttributeByName(org.w3c.dom.Node node, java.lang.String name)
Get the attribute with given name's value- Parameters:
node
- the node which attribute's value is returnedname
- name of the attribute- Returns:
- the value af the attribute
-
getElementTextValueDeprecated
public static java.lang.String getElementTextValueDeprecated(org.w3c.dom.Element parentNode)
Get the data of the element , no matter whether it is TXT ot CDATA- Parameters:
parentNode
- the node which data is returned- Returns:
- the TEXT or CDATA of the parentNode
-
setElementTextValue
public static void setElementTextValue(org.w3c.dom.Element e, java.lang.String data)
Sets element TEXT data- Parameters:
e
- the elementdata
- the new data
-
setElementCDataValue
public static void setElementCDataValue(org.w3c.dom.Element e, java.lang.String data)
Sets element CDATA data- Parameters:
e
- the lementdata
- the new data
-
getElementCDataValue
public static java.lang.String getElementCDataValue(org.w3c.dom.Element e)
Gets CDATA value of an element- Parameters:
e
- the element- Returns:
- CDATA value of element e
-
getElementCDataNode
public static org.w3c.dom.CDATASection getElementCDataNode(org.w3c.dom.Element element)
Returns element's CDATA Node- Parameters:
element
- the element which CDATA node is returned- Returns:
- CDATA node
-
getElementTextNode
public static org.w3c.dom.Text getElementTextNode(org.w3c.dom.Element element)
Returns element's TEXT Node- Parameters:
element
- the element which TEXT node is returned- Returns:
- TEXT node
-
getChildNodeByType
private static org.w3c.dom.Node getChildNodeByType(org.w3c.dom.Element element, short nodeType)
-
writeXML
public static void writeXML(java.io.File file, org.w3c.dom.Node node) throws java.io.FileNotFoundException
- Throws:
java.io.FileNotFoundException
-
writeXML
public static void writeXML(java.io.OutputStream outStream, org.w3c.dom.Node node)
-
writeXML
public static void writeXML(java.io.OutputStream outStream, org.w3c.dom.Node node, boolean indent)
-
writeXML
public static void writeXML(java.io.Writer writer, org.w3c.dom.Node node, boolean indent)
Writes the specified document to the given file. The default encoding is UTF-8.- Parameters:
out
- the output Filedocument
- the document to be writen
-
writeXML
public static void writeXML(java.io.Writer writer, org.w3c.dom.Document document, java.lang.String doctypeSystem, java.lang.String doctypePublic)
-
getChildElementByChain
public static org.w3c.dom.Element getChildElementByChain(org.w3c.dom.Element element, java.lang.String[] chain, boolean create)
Returns the element which is at the end of the specified chain... - Parameters:
element
-chain
-- Returns:
-
createLastPathComponent
public static org.w3c.dom.Element createLastPathComponent(org.w3c.dom.Document doc, java.lang.String[] path)
Creates (only if necessary) and returns the element which is at the end of the specified path.- Parameters:
doc
- the target document where the specified path should be createdpath
- a dot separated string indicating the path to be created- Returns:
- the component at the end of the newly created path.
-
getChildElementByTagNameNS
public static org.w3c.dom.Element getChildElementByTagNameNS(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String nsName)
-
getChildElementByTagName
public static org.w3c.dom.Element getChildElementByTagName(org.w3c.dom.Element parent, java.lang.String tagName)
Returns the child element with the specified tagName for the specified parent element- Parameters:
parent
-tagName
-- Returns:
-
getChildElementsByTagNameNS
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagNameNS(org.w3c.dom.Element parent, java.lang.String tagName, java.lang.String nsName)
-
getChildElementsByTagName
public static java.util.List<org.w3c.dom.Element> getChildElementsByTagName(org.w3c.dom.Element parent, java.lang.String tagName)
-
printChildElements
public static void printChildElements(org.w3c.dom.Element parent, java.io.PrintStream out, boolean deep, java.lang.String prefix)
Used for debuging- Parameters:
parent
- Elementout
- PrintStreamdeep
- booleanprefix
- String
-
-