Example usage for org.w3c.dom Document getElementsByTagName

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

Introduction

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

Prototype

public NodeList getElementsByTagName(String tagname);

Source Link

Document

Returns a NodeList of all the Elements in document order with a given tag name and are contained in the document.

Usage

From source file:WSpatern.getFileSecuirty.java

private void parseXML(String line) {

    try {//w ww.  j av a  2s  . c o m
        org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new StringReader(line)));
        NodeList response = doc.getElementsByTagName("securityLink");
        if (response.getLength() > 0) {
            for (int i = 0; i < response.getLength(); i++) {
                Element err = (Element) response.item(i);

                hasFull = err.getElementsByTagName("hasFull").item(0).getTextContent();
                hasRead = err.getElementsByTagName("hasRead").item(0).getTextContent();
                hasWrite = err.getElementsByTagName("hasWrite").item(0).getTextContent();
                secName = err.getElementsByTagName("secName").item(0).getTextContent();

                System.out.println("Full " + hasFull);
                System.out.println("Read" + hasRead);
                System.out.println("Write" + hasWrite);

            }

        }
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public String getStartAddress(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("start_address");
    Node node1 = nl1.item(0);//from   w  w  w. ja va2  s .c  om
    Log.i("StartAddress", node1.getTextContent());
    return node1.getTextContent();
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public String getEndAddress(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("end_address");
    Node node1 = nl1.item(0);//from ww  w .  j  a  v  a 2s . com
    Log.i("StartAddress", node1.getTextContent());
    return node1.getTextContent();
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public String getCopyRights(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("copyrights");
    Node node1 = nl1.item(0);//ww  w . ja  v a 2  s .  com
    Log.i("CopyRights", node1.getTextContent());
    return node1.getTextContent();
}

From source file:WSpatern.GetAllWorkflow.java

private void parseXML(String line) {

    try {// w  ww . j  a  va  2  s.c  o  m
        org.w3c.dom.Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new InputSource(new StringReader(line)));
        NodeList response = doc.getElementsByTagName("flowFileList");
        if (response.getLength() > 0) {
            for (int i = 0; i < response.getLength(); i++) {
                Element err = (Element) response.item(i);
                if (err.getElementsByTagName("fileName").getLength() > 0) {
                    w_flowname.add(err.getElementsByTagName("fileName").item(0).getTextContent());
                }

                if (err.getElementsByTagName("fileId").getLength() > 0) {
                    w_flowid.add(err.getElementsByTagName("fileId").item(0).getTextContent());
                }

                //category=err.getElementsByTagName("category").item(0).getTextContent();

            }

        }
    } catch (ParserConfigurationException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SAXException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(LoginWS.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:WpRDFFunctionLibrary.java

public static HashMap<String, String> getOrganismsTaxonomyMapping()
        throws ParserConfigurationException, SAXException, IOException {
    HashMap<String, String> hm = new HashMap<String, String>();
    WikiPathwaysClient wpClient = startWpApiClient();
    String[] wpOrganisms = wpClient.listOrganisms();
    for (String organism : wpOrganisms) {
        System.out.println(constants.getEUtilsUrl("taxonomy", organism.replace(" ", "_")));
        Document taxonomy = basicCalls
                .openXmlURL(constants.getEUtilsUrl("taxonomy", organism.replace(" ", "_")));
        try {//from  w ww .  j  a v  a 2  s. co  m
            String ncbiTaxonomy = taxonomy.getElementsByTagName("Id").item(0).getTextContent().trim();
            hm.put(organism, ncbiTaxonomy);
        } catch (Exception error) {
            System.out.println("ERROR: while getting taxonomy ID for organism: " + organism);
        }
    }
    return hm;
}

From source file:com.appdynamics.monitors.ehcache.EhcacheRESTWrapper.java

/**
  * Converts the inputstream retrieved from the connection to Ehcache host into a HashMap of metrics
  * @param is Inputstream retrieved from the connection to Ehcache host
  * @return   HashMap containing metrics for all the caches registered to this Ehcache host
  *//*  w w w.j  a va 2 s.  co m*/
private HashMap convertResponseToMap(InputStream is) throws Exception {
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    dbFactory.setNamespaceAware(true);
    DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
    Document doc = dBuilder.parse(is);

    NodeList caches = doc.getElementsByTagName(CACHE_NODE);
    HashMap<String, HashMap<String, Number>> metricsMap = new HashMap<String, HashMap<String, Number>>();
    for (int i = 0; i < caches.getLength(); i++) {
        Node cache = caches.item(i);
        NodeList cacheNodes = cache.getChildNodes();
        String cacheName = null;
        for (int j = 0; j < cacheNodes.getLength(); j++) {
            Node cacheNode = cacheNodes.item(j);
            if (cacheNode.getNodeName().equalsIgnoreCase(CACHE_NODE_NAME)) {
                cacheName = cacheNode.getTextContent();
                metricsMap.put(cacheNode.getTextContent(), new HashMap<String, Number>());
            }
            if (cacheNode.getNodeName().equalsIgnoreCase(CACHE_STATISTICS_NODE)) {
                NodeList statistics = cacheNode.getChildNodes();
                HashMap<String, Number> statisticsMap = new HashMap<String, Number>();
                for (int k = 0; k < statistics.getLength(); k++) {
                    Node statisticsNode = statistics.item(k);
                    Number value;
                    if (NumberUtils.isNumber(statisticsNode.getTextContent())) {
                        if (statisticsNode.getTextContent().contains(".")) {
                            value = Double.parseDouble(statisticsNode.getTextContent());
                        } else {
                            value = Long.parseLong(statisticsNode.getTextContent());
                        }
                        statisticsMap.put(statisticsNode.getNodeName(), value);
                    }
                }
                if (cacheName != null) {
                    metricsMap.put(cacheName, statisticsMap);
                }
            }
        }
    }
    return metricsMap;
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public String getDurationText(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("duration");
    Node node1 = nl1.item(0);/*from   w  w w. j ava  2s .  c  o  m*/
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "text"));
    Log.i("DurationText", node2.getTextContent());
    return node2.getTextContent();
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public int getDurationValue(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("duration");
    Node node1 = nl1.item(0);/*from   w ww  .  j  a  v  a 2s . c  o  m*/
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "value"));
    Log.i("DurationValue", node2.getTextContent());
    return Integer.parseInt(node2.getTextContent());
}

From source file:co.edu.uniajc.vtf.utils.GMapV2Direction.java

public String getDistanceText(Document doc) {
    NodeList nl1 = doc.getElementsByTagName("distance");
    Node node1 = nl1.item(0);/*from ww w . j av a2s  .  c  o  m*/
    NodeList nl2 = node1.getChildNodes();
    Node node2 = nl2.item(getNodeIndex(nl2, "text"));
    Log.i("DistanceText", node2.getTextContent());
    return node2.getTextContent();
}