Java Utililty Methods XML Element Root

List of utility methods to do XML Element Root

  1. HOME
  2. Java
  3. X
  4. XML Element Root

Description

The list of methods to do XML Element Root are organized into topic(s).

Method

Element createRoot(Document document, String title)
create Root
Element node = document.createElement(title);
node.setAttribute("xmlns", "http://www.supermap.com.cn/desktop");
node.setAttribute("version", "9.0.x");
document.appendChild(node);
return node;
Element createRootElement(Document doc, String name)
Create root element for specified document if it does not already exist and return it
return getRootElement(doc, true, name);
Element createRootElement(Document doc, String name)
Creates a root element for the specified document.
Element result = doc.createElement(name);
doc.appendChild(result);
return result;
Element createRootElement(Document doc, String rootTagName)
Create an root element with the specified name
if (doc.getDocumentElement() == null) {
 Element root = doc.createElement(rootTagName);
 doc.appendChild(root);
 return root;
return doc.getDocumentElement();
Node getElement(String elementName, Node rootNode)
get Element
Node node = rootNode.getFirstChild();
while (node != null) {
 if (node.getNodeName().equalsIgnoreCase(elementName)) {
 return node;
 node = node.getNextSibling();
return null;
...
String getElementData(final Element root, final String elementName)
Gets the text value of the specified element.
NodeList nodes = root.getElementsByTagName(elementName);
if (nodes.getLength() < 1) {
 return null;
return getElementData(nodes.item(0));
String getElementData(final Element root, final String elementName)
Gets the text value of the specified element.
NodeList nodes = root.getElementsByTagName(elementName);
if (nodes.getLength() < 1) {
 return null;
return getElementData(nodes.item(0));
String getElementText(String elemName, Element root, boolean trim)
get Element Text
Element elem = getFirstElement(elemName, root);
if (elem != null) {
 return getSimpleElementText(elem, trim);
} else {
 return null;
String getElementValue(Element root, String name)
get Element Value
try {
 return root.getElementsByTagName(name).item(0).getTextContent();
} catch (Exception e) {
 if (DEBUG) {
 System.out.println("element: " + name);
 System.out.println(printXML(root));
 throw e;
...
long getElementValueLong(Element root, String name)
get Element Value Long
String value = getElementValue(root, name).trim();
if (value.length() == 0 || "null".equalsIgnoreCase(value))
 return 0;
if ("unlimited".equalsIgnoreCase(value))
 return Long.MAX_VALUE;
try {
 return Long.parseLong(value);
} catch (Exception e) {
...


AltStyle によって変換されたページ (->オリジナル) /