Note that there are some explanatory texts on larger screens.

plurals
  1. POParsing xml document Java "cannot be resolved"
    text
    copied!<p>I'm going through a tutorial on how to parse an xml document with java and encountering a problem. I am getting the error "dom cannot be resolved" I know it has something to do with the way I am declaring the variables and being out of scope but I can't figure out how to fix it.</p> <p>Any help would be greatly appreciated, I will post the relevant parts below:</p> <pre><code>package com.xmlparse; import java.io.IOException; import java.util.Iterator; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import org.xml.sax.Attributes; import org.xml.sax.SAXException; import com.entities.Employee; public class XmlParser { private void parseXmlFile(){ //get the factory DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { //Using factory get an instance of document builder DocumentBuilder db = dbf.newDocumentBuilder(); //parse using builder to get DOM representation of the XML file Document dom = db.parse("test.xml"); } catch(ParserConfigurationException pce) { pce.printStackTrace(); } catch(SAXException se) { se.printStackTrace(); } catch(IOException ioe) { ioe.printStackTrace(); } } private void parseDocument() { Document dom = db.parse("test.xml"); //get the root element Element docEle = dom.getDocumentElement(); //get a nodelist of elements NodeList nl = docEle.getElementsByTagName("Employee"); if(nl != null &amp;&amp; nl.getLength() &gt; 0) { for(int i = 0 ; i &lt; nl.getLength(); i++) { //get the employee element Element el = (Element)nl.item(i); //get the Employee object Employee e = getEmployee(el); //add it to list myEmpls.add(e); } } } </code></pre>
 

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