title: RSS Unexpected Token, reading in xml file
body: <p>I'm trying to create a RSS Reader that reads in a Rss feed and displays it in a list view. I got his to work with other RSS Feeds but I can't get it to work on the Feed that I actually need it for. I validated the feed and it says that it is a valid RSS feed with no errors. I know that the problem/solution is in the <code>getDomFromXMLString</code> method which is where it is actually pulling the XML in, but I can't figure out how to make it read it is correctly.</p>
  
  <p>Here's my Main Activity</p>
  
  <pre><code>package com.example.lehi.events;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.NodeList;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ArrayAdapter;
  import android.widget.ListView;
  import android.widget.TextView;
  
  public class MainActivity extends Activity {
  
      String key_items = "item";
      String key_title = "title";
      String key_description = "description";
      String key_link = "link";
      String key_date = "pubDate";
      ListView lstPost = null;
      List&lt;HashMap&lt;String, Object&gt;&gt; post_lists = new ArrayList&lt;HashMap&lt;String, Object&gt;&gt;();
      List&lt;String&gt; lists = new ArrayList&lt;String&gt;();
      ArrayAdapter&lt;String&gt; adapter = null;
      RSSReader rssfeed = new RSSReader();
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          lstPost = (ListView) findViewById(R.id.lstPosts);
          adapter = new ArrayAdapter&lt;String&gt;(this,
                  android.R.layout.simple_list_item_2, android.R.id.text1, lists) {
  
              @Override
              public View getView(int position, View convertView, ViewGroup parent) {
                  View view = super.getView(position, convertView, parent);
                  TextView txt1 = (TextView) view
                          .findViewById(android.R.id.text1);
                  TextView txt2 = (TextView) view
                          .findViewById(android.R.id.text2);
                  HashMap&lt;String, Object&gt; data = post_lists.get(position);
                  txt1.setText(data.get(key_title).toString());
                  txt2.setText(data.get(key_description).toString());
                  return view;
              }
  
          };
          Document xmlFeed;
          xmlFeed = rssfeed.getRSSFromServer("http://calendar.byui.edu/RSSFeeds.aspx?data=hhAbVFpDFO7OxcTcYlM9Lk3inbX%2bJ%2baS3fubTE468TQI91kccS33vQ%3d%3d");
          NodeList nodes = xmlFeed.getElementsByTagName("item");
              for (int i = 0; i &lt; nodes.getLength(); i++) {
                  Element item = (Element) nodes.item(i);
                  HashMap&lt;String, Object&gt; feed = new HashMap&lt;String, Object&gt;();
                  feed.put(key_title, rssfeed.getValue(item, key_title));
                  feed.put(key_description, rssfeed.getValue(item, key_description));
                  feed.put(key_link, rssfeed.getValue(item, key_link));
                  feed.put(key_date, rssfeed.getValue(item, key_date));
                  post_lists.add(feed);
                  lists.add(feed.get(key_title).toString());
              }
              lstPost.setAdapter(adapter);
      }
  }
  </code></pre>
  
  <p>Here's the feed URL
  <a href="http://calendar.byui.edu/RSSFeeds.aspx?data=hhAbVFpDFO7OxcTcYlM9Lk3inbX%2bJ%2baS3fubTE468TQI91kccS33vQ%3d%3d" rel="nofollow">http://calendar.byui.edu/RSSFeeds.aspx?data=hhAbVFpDFO7OxcTcYlM9Lk3inbX%2bJ%2baS3fubTE468TQI91kccS33vQ%3d%3d</a></p>
  
  <p>Thanks</p>
  
  <p>Edit:
  Here's the object that rssfeed is being declared as.</p>
  
  <pre><code>import java.io.StringReader;
  
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.methods.HttpGet;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  import org.w3c.dom.Document;
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  
  import android.os.StrictMode;
  
  public class RSSReader {
      DefaultHttpClient httpClient = new DefaultHttpClient();
  
      public Document getRSSFromServer(String url) {
          Document response = null;
          response = getDomFromXMLString(getFeedFromServer(url));
          return response;
      }
  
      private String getFeedFromServer(String url) {
          String xml = null;
          if (android.os.Build.VERSION.SDK_INT &gt; 9) {
              StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
                      .permitAll().build();
              StrictMode.setThreadPolicy(policy);
          }
          try {
              HttpGet httpget =new HttpGet(url);
              HttpResponse httpResponse = httpClient.execute(httpget);
              HttpEntity httpEntity = httpResponse.getEntity();
              xml = EntityUtils.toString(httpEntity);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return xml;
      }
  
      private Document getDomFromXMLString(String xml) {
          Document doc = null;
          DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
          try {
              DocumentBuilder db = dbf.newDocumentBuilder();
              InputSource is = new InputSource();
              is.setCharacterStream(new StringReader(xml));
              doc = db.parse(is);
  
          } catch (Exception e) {
          }
          return doc;
      }
  
      public String getValue(Element item, String key) {
          NodeList nodeList = item.getElementsByTagName(key);
          return this.getElementValue(nodeList.item(0));
      }
  
      public final String getElementValue(Node node) {
          Node child;
          if (node != null) {
              if (node.hasChildNodes()) {
                  for (child = node.getFirstChild(); child != null; child = child
                          .getNextSibling()) {
                      if (child.getNodeType() == Node.TEXT_NODE) {
                          return child.getNodeValue();
                      }
                  }
              }
          }
          return "";
      }
  }
  </code></pre>
  
  <p>It's the <code>org.xml.sax.SAXParseException: Unexpected token (position:TEXT ï»¿@1:4 in java.io.StringReader@19916b6d)</code> that I am trying to figure out. </p>
  
  <pre><code>03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ org.xml.sax.SAXParseException: Unexpected token (position:TEXT ï»¿@1:4 in java.io.StringReader@19916b6d)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:146)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at com.example.lehi.events.RSSReader.getDomFromXMLString(RSSReader.java:58)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at com.example.lehi.events.RSSReader.getRSSFromServer(RSSReader.java:29)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at com.example.lehi.events.MainActivity.onCreate(MainActivity.java:56)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
  03-15 18:29:08.307    3612-3612/com.example.lehi.events W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
  03-15 18:29:08.308    3612-3612/com.example.lehi.events W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  03-15 18:29:08.308    3612-3612/com.example.lehi.events W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>