title: org.xml.sax.SAXParseException: Unexpected token (position:TEXT @1:2 in java.io.StringReader@4156ccc8)
body: <p>I have this code in my Main Activity:</p>
  
  <pre><code>BufferedReader reader = new BufferedReader (new InputStreamReader(in));
  
          StringBuilder xml1 = new StringBuilder();
          String cursor;
          try {
              while ( (cursor = reader.readLine()) != null){
                  xml1.append(cursor);
              }
          } catch (IOException e1) {
              // TODO Auto-generated catch block
              e1.printStackTrace();
          }
          String xml = xml1.toString();
  
                  XmlParser parser = new XmlParser();
          Document doc = parser.getDomElement(xml); 
  </code></pre>
  
  <p>And here is the getDomElement function: </p>
  
  <pre><code>public Document getDomElement(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 (ParserConfigurationException e) {
                  Log.e("Error: ", e.getMessage());
                  return null;
              } catch (SAXException e) {
                  Log.e("Error: ", e.getMessage());
                  return null;
              } catch (IOException e) {
                  Log.e("Error: ", e.getMessage());
                  return null;
              }
  
              return doc;
      }
  </code></pre>
  
  <p>Here is the XML File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;feed xml:base="https://portal.wow2.telenor.com/global/newscentre/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"&gt;
    &lt;id&gt;032acc78-4645-416d-8f57-69f9de340d9e&lt;/id&gt;
    &lt;title /&gt;
    &lt;updated&gt;2014-03-20T06:20:12Z&lt;/updated&gt;
  &lt;entry m:etag="&amp;quot;28&amp;quot;"&gt;
      &lt;id&gt;3cd3253c-7a95-4751-b34c-dada815c6d23&lt;/id&gt;
      &lt;category term="SP.Data.PagesItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /&gt;
      &lt;link rel="edit" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FirstUniqueAncestorSecurableObject" type="application/atom+xml;type=entry" title="FirstUniqueAncestorSecurableObject" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/FirstUniqueAncestorSecurableObject" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/RoleAssignments" type="application/atom+xml;type=feed" title="RoleAssignments" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/RoleAssignments" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/AttachmentFiles" type="application/atom+xml;type=feed" title="AttachmentFiles" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/AttachmentFiles" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ContentType" type="application/atom+xml;type=entry" title="ContentType" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/ContentType" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsHtml" type="application/atom+xml;type=entry" title="FieldValuesAsHtml" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/FieldValuesAsHtml" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesAsText" type="application/atom+xml;type=entry" title="FieldValuesAsText" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/FieldValuesAsText" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/FieldValuesForEdit" type="application/atom+xml;type=entry" title="FieldValuesForEdit" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/FieldValuesForEdit" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/File" type="application/atom+xml;type=entry" title="File" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/File" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/Folder" type="application/atom+xml;type=entry" title="Folder" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/Folder" /&gt;
      &lt;link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/ParentList" type="application/atom+xml;type=entry" title="ParentList" href="Web/Lists(guid'b1b97552-232e-46e3-b9ec-f864a85f7177')/Items(2)/ParentList" /&gt;
      &lt;title /&gt;
      &lt;updated&gt;2014-03-20T06:20:12Z&lt;/updated&gt;
      &lt;author&gt;
        &lt;name /&gt;
      &lt;/author&gt;
      &lt;content type="application/xml"&gt;
        &lt;m:properties&gt;
          &lt;d:FileSystemObjectType m:type="Edm.Int32"&gt;0&lt;/d:FileSystemObjectType&gt;
          &lt;d:Id m:type="Edm.Int32"&gt;2&lt;/d:Id&gt;
          &lt;d:ContentTypeId&gt;0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D000C4FEEB0930A3E4FAC4CED6DBC3688FA&lt;/d:ContentTypeId&gt;
          &lt;d:OData__ModerationComments m:null="true" /&gt;
          &lt;d:Title&gt;a1&lt;/d:Title&gt;
          &lt;d:OData__dlc_DocId&gt;67XPVZAHCTHM-7-2&lt;/d:OData__dlc_DocId&gt;
          &lt;d:OData__dlc_DocIdUrl m:type="SP.FieldUrlValue"&gt;
            &lt;d:Description&gt;67XPVZAHCTHM-7-2&lt;/d:Description&gt;
            &lt;d:Url&gt;https://portal.wow2.telenor.com/global/newscentre/_layouts/15/DocIdRedir.aspx?ID=67XPVZAHCTHM-7-2&lt;/d:Url&gt;
          &lt;/d:OData__dlc_DocIdUrl&gt;
          &lt;d:Comments m:null="true" /&gt;
          &lt;d:PublishingStartDate m:null="true" /&gt;
          &lt;d:PublishingExpirationDate m:null="true" /&gt;
          &lt;d:PublishingContactId m:type="Edm.Int32"&gt;1&lt;/d:PublishingContactId&gt;
          &lt;d:PublishingContactEmail m:null="true" /&gt;
          &lt;d:PublishingContactName m:null="true" /&gt;
          &lt;d:PublishingContactPicture m:null="true" /&gt;
          &lt;d:PublishingPageLayout m:type="SP.FieldUrlValue"&gt;
            &lt;d:Description&gt;Body only&lt;/d:Description&gt;
            &lt;d:Url&gt;https://portal.wow2.telenor.com/_catalogs/masterpage/PageFromDocLayout.aspx&lt;/d:Url&gt;
          &lt;/d:PublishingPageLayout&gt;
          &lt;d:PublishingIsFurlPage m:type="Edm.Boolean"&gt;true&lt;/d:PublishingIsFurlPage&gt;
          &lt;d:SeoBrowserTitle m:null="true" /&gt;
          &lt;d:SeoMetaDescription m:null="true" /&gt;
          &lt;d:SeoKeywords m:null="true" /&gt;
          &lt;d:RobotsNoIndex m:type="Edm.Boolean"&gt;false&lt;/d:RobotsNoIndex&gt;
          &lt;d:PublishingPageContent&gt;&amp;lt;p&amp;gt;test​&amp;lt;/p&amp;gt;&lt;/d:PublishingPageContent&gt;
          &lt;d:ArticleByLine m:null="true" /&gt;
          &lt;d:ArticleStartDate m:null="true" /&gt;
          &lt;d:PublishingImageCaption m:null="true" /&gt;
          &lt;d:TelenorBanner m:null="true" /&gt;
          &lt;d:BusinessUnit&gt;
            &lt;d:element m:type="SP.Taxonomy.TaxonomyFieldValue"&gt;
              &lt;d:Label&gt;Global&lt;/d:Label&gt;
              &lt;d:TermGuid&gt;95e90ed7-544b-4526-8479-b829dbf448f6&lt;/d:TermGuid&gt;
              &lt;d:WssId m:type="Edm.Int32"&gt;4&lt;/d:WssId&gt;
            &lt;/d:element&gt;
          &lt;/d:BusinessUnit&gt;
          &lt;d:GeoLocation m:null="true" /&gt;
          &lt;d:SecurityClassification&gt;Internal&lt;/d:SecurityClassification&gt;
          &lt;d:RightColumnContact m:null="true" /&gt;
          &lt;d:InformationContentType m:null="true" /&gt;
          &lt;d:InformationContextCategory m:null="true" /&gt;
          &lt;d:InformationValue&gt;Non-Essential&lt;/d:InformationValue&gt;
          &lt;d:TelenorArticleFirstPublishDate m:null="true" /&gt;
          &lt;d:ArticleAuthorId m:null="true" /&gt;
          &lt;d:ArticleCoAuthorsId m:null="true" /&gt;
          &lt;d:Teaser m:null="true" /&gt;
          &lt;d:Introduction m:null="true" /&gt;
          &lt;d:EnableComments m:type="Edm.Boolean"&gt;true&lt;/d:EnableComments&gt;
          &lt;d:IsHighlight m:type="Edm.Boolean"&gt;false&lt;/d:IsHighlight&gt;
          &lt;d:ArticleLanguage m:type="SP.Taxonomy.TaxonomyFieldValue"&gt;
            &lt;d:Label&gt;1&lt;/d:Label&gt;
            &lt;d:TermGuid&gt;23c0f277-1348-4971-aac7-9bba7d153ecf&lt;/d:TermGuid&gt;
            &lt;d:WssId m:type="Edm.Int32"&gt;1&lt;/d:WssId&gt;
          &lt;/d:ArticleLanguage&gt;
          &lt;d:ArticleSummaryLinkText m:null="true" /&gt;
          &lt;d:TelenorArticlePublishingDate&gt;2014-02-06T10:28:21Z&lt;/d:TelenorArticlePublishingDate&gt;
          &lt;d:EnableCommentsWebArtice m:type="Edm.Boolean"&gt;false&lt;/d:EnableCommentsWebArtice&gt;
          &lt;d:AggregateTarget /&gt;
          &lt;d:Set_x0020_Publish_x0020_Date m:null="true" /&gt;
          &lt;d:Set_x0020_Publish_x0020_Date_x0028_1_x0029_ m:null="true" /&gt;
          &lt;d:AverageRating m:null="true" /&gt;
          &lt;d:RatingCount m:null="true" /&gt;
          &lt;d:LikesCount m:null="true" /&gt;
          &lt;d:OData__ModerationStatus m:type="Edm.Int32"&gt;0&lt;/d:OData__ModerationStatus&gt;
          &lt;d:ID m:type="Edm.Int32"&gt;2&lt;/d:ID&gt;
          &lt;d:Created m:type="Edm.DateTime"&gt;2013-07-09T05:59:34Z&lt;/d:Created&gt;
          &lt;d:AuthorId m:type="Edm.Int32"&gt;1&lt;/d:AuthorId&gt;
          &lt;d:Modified m:type="Edm.DateTime"&gt;2014-02-06T10:28:21Z&lt;/d:Modified&gt;
          &lt;d:EditorId m:type="Edm.Int32"&gt;3974&lt;/d:EditorId&gt;
          &lt;d:OData__CopySource m:null="true" /&gt;
          &lt;d:CheckoutUserId m:null="true" /&gt;
          &lt;d:OData__UIVersionString&gt;6.0&lt;/d:OData__UIVersionString&gt;
          &lt;d:GUID m:type="Edm.Guid"&gt;1bb37159-2438-4693-acab-ceef4b5a8214&lt;/d:GUID&gt;
        &lt;/m:properties&gt;
      &lt;/content&gt;
    &lt;/entry&gt;
    &lt;link rel="next" href="https://portal.wow2.telenor.com/global/newscentre/_api/web/lists('b1b97552-232e-46e3-b9ec-f864a85f7177')/items?%24skiptoken=Paged%3dTRUE%26p_SortBehavior%3d0%26p_ID%3d1288&amp;amp;%24%24orderby=Created+dsc" /&gt;
  &lt;/feed&gt;
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>org.xml.sax.SAXParseException: Unexpected token (position:TEXT @1:2 in java.io.StringReader@4156ccc8) at the StringReader
  </code></pre>
  
  <p>Also I am not getting the whole XML file displayed when I display it in Logcat after converting it to String.</p>