Example usage for org.w3c.dom Element getElementsByTagName

List of usage examples for org.w3c.dom Element getElementsByTagName

Introduction

In this page you can find the example usage for org.w3c.dom Element getElementsByTagName.

Prototype

public NodeList getElementsByTagName(String name);

Source Link

Document

Returns a NodeList of all descendant Elements with a given tag name, in document order.

Usage

From source file:com.aurel.track.admin.customize.category.report.ReportBL.java

private static String getTagValue(String sTag, Element eElement) {
    try {/*from   ww w.ja  v  a  2  s.co  m*/
        NodeList nlList = eElement.getElementsByTagName(sTag).item(0).getChildNodes();
        Node nValue = nlList.item(0);
        return nValue.getNodeValue();
    } catch (Exception e) {
        LOGGER.warn("Getting the tag value " + sTag + " failed with " + e.getMessage());
        return null;
    }
}

From source file:de.codesourcery.jasm16.emulator.EmulationOptions.java

private static Element getChildElement(Element parent, String tagName) {
    final NodeList nodeList = parent.getElementsByTagName(tagName);
    if (nodeList.getLength() == 1) {
        return (Element) nodeList.item(0);
    }/*from  www . j av a 2s .c o  m*/
    if (nodeList.getLength() > 1) {
        throw new RuntimeException("Parse error, more than one <disks/> node in file?");
    }
    return null;
}

From source file:com.moviejukebox.tools.DOMHelper.java

/**
 * Get an element from a parent element node
 *
 * @param eParent//  w w  w.  j a  va2  s . c o m
 * @param elementName
 * @return
 */
public static Element getElementByName(Element eParent, String elementName) {
    NodeList nlParent = eParent.getElementsByTagName(elementName);
    for (int looper = 0; looper < nlParent.getLength(); looper++) {
        if (nlParent.item(looper).getNodeType() == Node.ELEMENT_NODE) {
            return (Element) nlParent.item(looper);
        }
    }
    return null;
}

From source file:de.akra.idocit.wsdl.services.DocumentationParser.java

/**
 * Searches for the first documentation element in <code>documentationElements</code>
 * containing docpart elements and parses the docpart elements.
 * /*from   w  w  w  . ja v a 2  s.  c o  m*/
 * @param documentationElements
 *            List of documentation elements that should be parsed.
 * @return {@link List} of {@link Documentation}s; one {@link Documentation}
 *         represents one docpart element. If no documentation element with docpart
 *         elements is found, {@link Collections#emptyList()} is returned.
 */
public static List<Documentation> parseDocElements(List<Element> documentationElements) {
    List<Documentation> documentations = Collections.emptyList();
    if (documentationElements != null) {
        Element docElem = findDocElemWithDocpart(documentationElements);

        if (docElem != null) {
            NodeList docParts = docElem.getElementsByTagName(DocumentationParser.DOCPART_TAG_NAME);

            documentations = new ArrayList<Documentation>(docParts.getLength());

            for (int i = 0; i < docParts.getLength(); i++) {
                Node dPart = docParts.item(i);
                Documentation doc = DocumentationParser.parseDocPartElement(dPart);
                documentations.add(doc);
            }
        }
    }

    return documentations;
}

From source file:edu.stanford.muse.webapp.Sessions.java

private static void addXmlTagToMap(Map<String, String> map, Element e, String tag, boolean optional) {
    NodeList nl = e.getElementsByTagName(tag);
    if (optional && (nl == null || nl.getLength() == 0)) {
        map.put(tag, null);/*  w  w w.j ava  2s .  c o  m*/
        return;
    }
    int len = nl != null ? nl.getLength() : 0;
    assert (nl != null && len == 1);
    Node node = nl.item(0).getFirstChild();
    if (node == null) {
        // blank config => null
        map.put(tag, null);
    } else {
        map.put(tag, node.getNodeValue());
    }
}

From source file:edu.harvard.i2b2.eclipse.plugins.workplace.util.XmlUtil.java

public static String getPatientId(XmlValueType xml) {
    Element rootElement = xml.getAny().get(0);
    NodeList nameElements = rootElement.getElementsByTagName("patient_id");
    if (nameElements.getLength() != 0) {
        return nameElements.item(0).getTextContent();
    } else//from ww  w.ja v a 2 s. com
        return MessageUtil.getInstance().getTimestamp();

}

From source file:edu.harvard.i2b2.eclipse.plugins.workplace.util.XmlUtil.java

public static String getSiteId(XmlValueType xml) {
    Element rootElement = xml.getAny().get(0);
    NodeList nameElements = rootElement.getElementsByTagName("patient_id");
    if (nameElements.getLength() != 0 && nameElements.item(0).getAttributes().getLength() != 0) {
        return nameElements.item(0).getAttributes().item(0).getTextContent();
    } else/*from  w w w  . j  av  a 2  s.com*/
        return "";//MessageUtil.getInstance().getTimestamp();

}

From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java

public static String getPatientId(XmlValueType xml) {
    Element rootElement = xml.getAny().get(0);
    NodeList nameElements = rootElement.getElementsByTagName("patient_id");
    if (nameElements.getLength() != 0) {
        return nameElements.item(0).getTextContent();
    } else {/*from w w  w  .  jav a  2s  . c  o m*/
        return null;//MessageUtil.getInstance().getTimestamp();
    }
}

From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java

public static String getSiteId(XmlValueType xml) {
    Element rootElement = xml.getAny().get(0);
    NodeList nameElements = rootElement.getElementsByTagName("patient_id");
    if (nameElements.getLength() != 0 && nameElements.item(0).getAttributes().getLength() != 0) {
        return nameElements.item(0).getAttributes().item(0).getTextContent();
    } else// w w  w  .  j  av a2 s. c  o m
        return null;//MessageUtil.getInstance().getTimestamp();

}

From source file:edu.harvard.i2b2.eclipse.plugins.query.utils.XmlUtil.java

public static String getIndex(XmlValueType xml) {
    Element rootElement = xml.getAny().get(0);
    NodeList indexElements = rootElement.getElementsByTagName("index");
    if (indexElements.getLength() == 0)
        return null;

    return indexElements.item(0).getTextContent();
}