Hi People.I was trying to access the data from an URL.Below are my codes.Can anybody correct me? I am sort of new to this.
package com.java.connect.dom4j; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.jar.Attributes.Name; import org.dom4j.*; import org.dom4j.io.SAXReader; //import org.dom4j.Document; //import org.dom4j.DocumentException; //import org.dom4j.Node; //import org.dom4j.io.SAXReader; public class Document { public static void main(String[] args) { // Get the SAXReader object SAXReader reader = new SAXReader(); // Get the xml document object by sax reader. org.dom4j.Document document = null; try { document = reader.read((new URL("http://www.fao.org/countryprofiles/geoinfo/ws/allCountries/EN.xml"))); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } // Define the xpath String xpathExpression = "//Data/self_governing"; // Get the list of nodes on given xPath private org.dom4j.Document document; List <Node> nodes = document.selectNodes(xpathExpression); // Read all the node inside xpath nodes and print the value of each for (Node node : nodes) { Node codeISO3= node.selectSingleNode("codeISO3"); System.out.println("CodeISO3 : " + codeISO3.getText()); Node name = node.selectSingleNode("codeISO2"); System.out.println("CodeISO2 : " + name.getText()); Node officialname = node.selectSingleNode("nameOfficialEN"); System.out.println("Official Name : " + officialname.getText()); Node shortname = node.selectSingleNode("nameShortEN"); System.out.println("Short Name : " + shortname.getText()); Node namelist = node.selectSingleNode("nameListEN"); System.out.println("Name List: " + namelist.getText()); Node fao = node.selectSingleNode("FAO_MEMBERS"); System.out.println("FAO members : " + fao.getText()); } } }
These are the errors I get.
The import node cannot be resolved line 5
node cannot be resolved to a type line 9
The method read(URL) is undefined for the type SAXReader line 26
The method selectNodes(String) from the type Document refers to the missing type node line 39
Somebody please help


LinkBack URL
About LinkBacks
Reply With Quote