Click here to Skip to main content
15,913,243 members
Home / Discussions / Java
   

Java

 
GeneralRe: JTextArea problem Pin
Alok Sharma ji26-Apr-12 23:22
Alok Sharma ji26-Apr-12 23:22 
Questiona question about ThreadPool Pin
dirk.zhang22-Apr-12 22:29
dirk.zhang22-Apr-12 22:29 
AnswerRe: a question about ThreadPool Pin
Nagy Vilmos23-Apr-12 0:21
professionalNagy Vilmos23-Apr-12 0:21 
Questionsparql query Pin
RORY1720-Apr-12 8:00
RORY1720-Apr-12 8:00 
AnswerRe: sparql query Pin
Nagy Vilmos23-Apr-12 1:56
professionalNagy Vilmos23-Apr-12 1:56 
GeneralRe: sparql query Pin
RORY1725-Apr-12 11:06
RORY1725-Apr-12 11:06 
QuestionProblems deploying Soap MTOM service WCF with Java Client Pin
sfinxrecord1319-Apr-12 4:30
sfinxrecord1319-Apr-12 4:30 
QuestionRead XML data into an ArrayList Pin
Chris_B8419-Apr-12 0:08
Chris_B8419-Apr-12 0:08 
Hi. Sorry, I am fairly new to Java. I am trying to read data from an XML file into an ArrayList. Here is the code:

Java
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class XmlParser {

		public void UserListParser() throws ParserConfigurationException{
			DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
			builder = dbfactory.newDocumentBuilder();
			XPathFactory xpfactory = XPathFactory.newInstance();
			path = xpfactory.newXPath();
		}
		
		
			//Parses an XML file containing the users.
			//@return an arraylist containing all users in the XML file
		
		public ArrayList<User> parse() throws SAXException, IOException, XPathExpressionException {
			File f = new File("../../../../../users.xml");
			Document doc = builder.parse(f);
			
			ArrayList<User> users = new ArrayList<User>();
			int count = Integer.parseInt(path.evaluate("count(/users/user)", doc));
			
			for (int i = 1; i <= count; i++) {
				String username = path.evaluate("users/user/[" + i + "]username", doc);
				String password = path.evaluate("users/user/[" + i + "]password", doc);
				String perms = path.evaluate("users/user/[" + i + "]permissions", doc);

				User u = new User(username, password, perms);
				users.add(u);		
			}
			
			return users;	
		
		}
		

}


I keep getting 7 errors, each error is one of the following and they are on lines 20, 22, 31, 34, 37, 38 and 39.

"Cannot find symbol"
symbol : variable builder

"Cannot find symbol"
symbol : variable path



Appreciate any help and thanks in advance. The XML file is below:

<?xml version="1.0" encoding="ISO-8859-1"?>
<users>
	<user>
		<username>User1</username>
		<password>Password1</password>
		<permissions>axxx</permissions>		
	</user>
	<user>
		<username>User2</username>
		<password>Password2</password>
		<permissions>xsxx</permissions>		
	</user>
	<user>
		<username>User3</username>
		<password>Password3</password>
		<permissions>xxbx</permissions>		
	</user>
	<user>
		<username>User4</username>
		<password>Password4</password>
		<permissions>xxxm</permissions>		
	</user>
</users>

AnswerRe: Read XML data into an ArrayList Pin
Richard MacCutchan19-Apr-12 1:39
mveRichard MacCutchan19-Apr-12 1:39 
AnswerRe: Read XML data into an ArrayList Pin
Ramesh221726-Apr-12 20:48
Ramesh221726-Apr-12 20:48 
Questionserial numbers in Java Application Pin
TorstenH.16-Apr-12 3:54
TorstenH.16-Apr-12 3:54 
AnswerRe: serial numbers in Java Application Pin
Nagy Vilmos16-Apr-12 4:50
professionalNagy Vilmos16-Apr-12 4:50 
GeneralRe: serial numbers in Java Application Pin
TorstenH.16-Apr-12 21:06
TorstenH.16-Apr-12 21:06 
AnswerRe: serial numbers in Java Application Pin
BobJanova16-Apr-12 5:37
BobJanova16-Apr-12 5:37 
GeneralRe: serial numbers in Java Application Pin
TorstenH.16-Apr-12 21:04
TorstenH.16-Apr-12 21:04 
QuestionTelephone Interface Pin
muhammed_k13-Apr-12 22:22
muhammed_k13-Apr-12 22:22 
AnswerRe: Telephone Interface Pin
Richard MacCutchan13-Apr-12 22:25
mveRichard MacCutchan13-Apr-12 22:25 
GeneralRe: Telephone Interface Pin
muhammed_k14-Apr-12 0:56
muhammed_k14-Apr-12 0:56 
Questionhow to set the files become read only using java rmi Pin
dnafrinsi13-Apr-12 22:06
dnafrinsi13-Apr-12 22:06 
SuggestionRe: how to set the files become read only using java rmi Pin
Richard MacCutchan13-Apr-12 22:23
mveRichard MacCutchan13-Apr-12 22:23 
GeneralRe: how to set the files become read only using java rmi Pin
dnafrinsi17-Apr-12 2:16
dnafrinsi17-Apr-12 2:16 
GeneralRe: how to set the files become read only using java rmi Pin
Richard MacCutchan17-Apr-12 4:53
mveRichard MacCutchan17-Apr-12 4:53 
QuestionHow to Delete/remove index elements in 2D arrayList Pin
B.Bryce10-Apr-12 2:48
B.Bryce10-Apr-12 2:48 
AnswerRe: How to Delete/remove index elements in 2D arrayList Pin
Richard MacCutchan10-Apr-12 5:38
mveRichard MacCutchan10-Apr-12 5:38 
GeneralRe: How to Delete/remove index elements in 2D arrayList Pin
B.Bryce10-Apr-12 7:11
B.Bryce10-Apr-12 7:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.