getNodeName(), but the value is always null. In other uses, I have done getTextContent(), but that doesn't seem to be an option. Has anyone else run into this? Here is my code just show an example.
Using java Syntax Highlighting
- public void getSearch(String strURL) {
- // Connect to WH API - SEARCH FUNCTION
- URL url;
- URLConnection urlConn = null;
- mainList = new ArrayList<Listy>();
- try {
- url = new URL(strURL);
- urlConn = url.openConnection();
- } catch (IOException ioe) {
- contentdiv.setText("Could not Connect: "+ioe.getMessage());
- }
- Document doc = null;
- try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- doc = db.parse(urlConn.getInputStream());
- String sid="", spage="", sname="", syear="", sim="";
- Node thisNode, currentNode; NodeList nchild, nodeList;
- nodeList = doc.getElementsByTagName("item");
- int length = nodeList.getLength();
- for (int i = 0; i < length; i++)
- {
- currentNode = nodeList.item(i);
- nchild = currentNode.getChildNodes();
- int clength = nchild.getLength();
- for (int j = 0; j < clength; j++)
- {
- thisNode = nchild.item(j);
- String value = thisNode.getNodeValue();
- if("id".equals(thisNode.getNodeName())){sid = value;}
- if("page".equals(thisNode.getNodeName())){spage = value;}
- if("name".equals(thisNode.getNodeName())){sname = value;}
- if("year".equals(thisNode.getNodeName())){syear = value;}
- if("im".equals(thisNode.getNodeName())){sim = value;}
- }
- mainList.add(new Listy(sid,sname,spage,syear,sim));
- }
- mFavList.setAdapter(new ArrayAdapter<Listy>(this,android.R.layout.simple_list_item_1, mainList));
- }
- catch (ParserConfigurationException pce){contentdiv.setText("Could not Parse XML: "+pce.getMessage());}
- catch (SAXException se) {contentdiv.setText("Could not Parse XML: "+se.getMessage());}
- catch (IOException ioe) {contentdiv.setText("Invalid XML: "+ioe.getMessage());}
- }
Parsed in 0.180 seconds, using GeSHi 1.0.8.4
The XML is encoded in UTF-8, could that be causing the problem?
Using xml Syntax Highlighting
- <?xml version='1.0' encoding='UTF-8'?>
- <searchy>
- <item>
- <id>1</id>
- <page>person</page>
- <name>Guy</name>
- <year>1980</year>
- <im>None</im>
- </item>
- <item>
- <id>2</id>
- <page>person</page>
- <name>Other Guy</name>
- <year>1985</year>
- <im>None</im>
- </item>
- </searchy>
Parsed in 0.014 seconds, using GeSHi 1.0.8.4
If I change a line in the code to have value = thisNode.getNodeName();, it displays the Node Names correctly. But the Node value, is always null...
Any thoughts (other than just using SAX). Thanks in advance!







