Jump to content

Recommended Posts

Posted

Muito boa noite,

Encontro-me a desenvolver um projecto um tanto o quanto complexo para mim, mas estou certo de que não o será para vós:)

Basicamente o que faz é usar querys de YQL (Yhaoo Query Language) em que recebo um Ficheiro xml.

Seguidamente tenho de processar esse XML de forma a criar objectos para atravéz de uma camada DAO os inserir na base de dados;

Qual o problema? Processar o dito XML...

Alguém me pode ajudar?

tenho isto neste momento mas está a estoirar:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package les.downloader;
import dao.Commodities;
import dao.Commodity;
import java.io.IOException;
import java.io.StringReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.lang.model.element.Element;
import javax.swing.text.Document;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
/**
*
* @author Pedro
*/
public class XProcessor implements IProcessor{
@Override

public boolean process(StringBuilder b) {
	 boolean res = false;
	try {


  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
  DocumentBuilder db = dbf.newDocumentBuilder();	
  InputSource is = new InputSource(new StringReader(b.toString()));			  
  Document doc = (Document) db.parse(is);

  Element el = doc.getDocumentElement() ell;
  NodeList nl= el.getElementsByTagName("results"), quote;

   for(int i = 0 ; i<nl.getLength();i++){
			el=(Element)nl.item(i);
			String symbol = el.getAttribute("symbol");
			quote = el.getElementsByTagName("quote");
			ell=(Element) null.item(0);
			String quote = ell.getNodeValue();
			Commodity cm = new Commodity();
			Commodities cmds = new Commodities();
			cm.setName(symbol);
			cmds.add(cm);
			cm.setName(quote);
			cmds.add(cm);
		}


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

}
Posted

Repara: tu colocas-nos uma classe que não corre sozinha e dizes-nos que está a "estoirar", sem qualquer indicação de qual é o erro que te está a dar... Assim não consegues grande ajuda.

  • Vote 1

“There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult.”

-- Tony Hoare

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.