Advertisement

06.03.2008 at 01:30PM PDT, ID: 23454600 | Points: 500
[x]
Attachment Details

encoding problem with cyberneko

Asked by oleber in Java Programming Language, JAXP & SAX (XML APIs), Java Standard Edition

I'm having some encoding problems in the prints. Just run it ;)

Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
import org.cyberneko.html.parsers.DOMParser;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
 
public class Test {
	public static void main(String[] args) throws Exception {
		DOMParser parser = new DOMParser();
		parser.parse("http://jn.sapo.pt/paginainicial/ultimas/default.aspx");
 
		Document doc = parser.getDocument();		
		print(doc);
	}
 
	static void print(Node node) throws Exception {
		NodeList nodelist = node.getChildNodes();
		
		for (int i=0; i<nodelist.getLength(); i++) {
			Node subnode = nodelist.item(i);
			switch (subnode.getNodeType()) {
			case Node.ELEMENT_NODE:
				Element element = (Element)subnode;
				print(element);
				break;
			case Node.TEXT_NODE:
				System.out.println(subnode.getTextContent().trim());
				break;
			}
		}
	}	
}
[+][-]06.04.2008 at 11:08AM PDT, ID: 21712473

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628