Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Edit : You have a bad import :</p> <p>replace : import android.renderscript.Element;</p> <p>by : import org.w3c.dom.Element;</p> <p>Then to help you :</p> <p>If you use DOMParser, here is some helping methods :</p> <pre><code>private String getNodeValueByTagName(Node parentNode, String tagNameOfNode) { String nodeValue = ""; if (((Element) parentNode).getElementsByTagName(tagNameOfNode).getLength() != 0) if (((Element) ((Element) parentNode).getElementsByTagName(tagNameOfNode).item(0)).hasChildNodes()) { nodeValue = ((Node) ((Element) ((Element) parentNode).getElementsByTagName(tagNameOfNode).item(0)).getChildNodes().item(0)).getNodeValue(); } return nodeValue; } private String getNodeAttributeByTagName(Node parentNode, String tagNameOfAttr) { String nodeValue = ""; NamedNodeMap questNodeAttr = parentNode.getAttributes(); if (questNodeAttr.getLength() != 0) nodeValue = questNodeAttr.getNamedItem(tagNameOfAttr).getTextContent(); return nodeValue; } </code></pre> <p>Then in your example :</p> <pre><code> DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); dbFactory.setCoalescing(true); //If you use CDATA in your nodes DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(f); doc.getDocumentElement().normalize(); NodeList staffNodeList = doc.getElementsByTagName("staff"); for (int i = 0; i &lt; staffNodeList.getLength(); i++) { Node staffNode = staffNodeList.item(i); String firstNameString = getNodeValueByTagName(staffNode, "firstname"); String lastNameString = getNodeValueByTagName(staffNode, "lastname"); String nickNameString = getNodeValueByTagName(staffNode, "nickname"); String salaryString = getNodeValueByTagName(staffNode, "salary"); int salaryInt = (salaryString.equals(""))?0:Integer.parseInt(salaryString); // TODO : Place your code here! } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload