public class XMLUtil extends Object
Modifier and Type | Field and Description |
---|---|
protected static org.slf4j.Logger |
log |
Modifier and Type | Method and Description |
---|---|
static Element |
addElement(Element parent,
String name)
Adds a child element to the parent.
|
static Element |
addElement(Node parent,
String name,
String value)
Adds a new child element to a parent.
|
static Element |
addElementNS(Element parent,
String prefix,
String name) |
static Element |
addElementNS(Node parent,
String prefix,
String name,
String value)
Adds a new child element to a parent with a namespace.
|
static boolean |
addNamespaceURIs(Document doc,
Map<String,String> nsMap) |
static boolean |
changeTagName(Element elem,
String newName)
Changes the tag name of an element.
|
static Document |
createDocument()
Returns a document newly created by the class's static DocumentBuilder.
|
static Element |
createDocument(String rootElemName) |
static Element |
createDocumentNS(String prefix,
String rootElemName,
Map<String,String> nsMap) |
static Element |
findFirstChild(Node parent,
String tagName)
Finds the first (direct) child Element with a given tag name.
|
static Element |
findFirstChildDeep(Document doc,
String tagName)
Returns the first element which name matchtes a given tag name.
|
static Element |
findFirstChildDeep(Element parent,
String tagName)
Finds the first element which name matchtes a given tag name
that is locacted anywhere below the given parent.
|
static Element |
findFirstChildWithAttrib(Node parent,
String tagName,
String attrName,
Object value)
Finds the first (direct) child element with a given tag name and attribute.
|
static String |
getChildText(Node parent,
String childName)
Returns the text value of a given child element.
|
static DocumentBuilder |
getDocumentBuilder()
Returns an initialzed, namespace aware DocumentBuilder.
|
static String |
getElementText(Node elem)
Retrieves the text of a given element.
|
static Element |
getFirstChild(Node parent)
Gets the first (direct) child Element.
|
static String |
getNamespaceURI(Document doc,
String prefix) |
static Element |
getNextSiblingElement(Element child,
boolean sameName)
Returns the next sibling Element for an element, optionally matching tag names.
|
static Element |
insertElement(Node parent,
String name,
Element pos) |
static Element |
insertElement(Node parent,
String name,
String value,
Element pos)
Inserts a new child element to a parent.
|
static Element |
insertElementNS(Node parent,
String prefix,
String name,
Element pos) |
static Element |
insertElementNS(Node parent,
String prefix,
String name,
String value,
Element pos)
Inserts a new child element to a parent.
|
static boolean |
setElementText(Node elem,
Object text)
Sets the text value of an Element.
|
public static Document createDocument()
public static DocumentBuilder getDocumentBuilder()
public static Element createDocumentNS(String prefix, String rootElemName, Map<String,String> nsMap)
public static Element getFirstChild(Node parent)
parent
- the parent element below which to search the childpublic static Element findFirstChild(Node parent, String tagName)
parent
- the parent element below which to search the childtagName
- the (tag) name of the desired child elementpublic static Element getNextSiblingElement(Element child, boolean sameName)
child
- the element from which to search for a next siblingsameName
- true to retrive the next sibling element of the same name, of false if any name is allowedpublic static Element findFirstChildWithAttrib(Node parent, String tagName, String attrName, Object value)
parent
- the parent element below which to search the childtagName
- the (tag) name of the desired child elementattrName
- the name of the attribute which value must match the given valuevalue
- the attribute value to which elements are matched.public static Element findFirstChildDeep(Element parent, String tagName)
parent
- the parent element below which to search the childtagName
- the (tag) name of the desired child elementpublic static Element findFirstChildDeep(Document doc, String tagName)
doc
- the xml document in which to find an element of the given nametagName
- the (tag) name of the desired child elementpublic static String getElementText(Node elem)
elem
- the Element for which the text value is requestedpublic static boolean setElementText(Node elem, Object text)
elem
- the Element for which the text value should be settext
- the new text value of the elementpublic static Element addElement(Node parent, String name, String value)
parent
- the Element to which to append the childname
- the (tag) name of the new childvalue
- the text value of the new element. (can be null!)public static Element addElement(Element parent, String name)
parent
- name
- public static Element addElementNS(Node parent, String prefix, String name, String value)
parent
- the Element to which to append the childprefix
- the name of the namespace this element belongs toname
- the (tag) name of the new childvalue
- the text value of the new element. (can be null!)public static Element insertElement(Node parent, String name, String value, Element pos)
parent
- the Element to which to append the childname
- the (tag) name of the new childvalue
- the text value of the new element. (can be null!)pos
- the inserted element will be placed before this elementpublic static Element insertElementNS(Node parent, String prefix, String name, String value, Element pos)
parent
- the Element to which to append the childprefix
- name
- the (tag) name of the new childvalue
- the text value of the new element. (can be null!)pos
- pos the inserted element will be placed before this elementpublic static Element insertElementNS(Node parent, String prefix, String name, Element pos)
public static String getChildText(Node parent, String childName)
parent
- the Element which contains the childchildName
- the (tag) name of the childCopyright © 2008–2015 Apache Software Foundation. All rights reserved.