Android XML Parsing error PImust not start with XML

Posted on 2012-09-09
Last Modified: 2012-09-28

Im new to Android and this is my first attempt at building a listview  and consuming a REST webservice into the ListView. I have built a REST webservice using visual Studio 2010, tested and working fine. The XML result is the following:

- <ArrayOfBookDetails xmlns:i="">
- <BookDetails>
  <Level>Keen Reader</Level>

This is done using the folowing Contract and Datamember:

        [WebGet(RequestFormat = WebMessageFormat.Xml,
            ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Bare
        BookDetails[] GetAllBooks();

[DataContract(Name = "BookDetails", Namespace = "")]
    public class bookDetails
        public int BookId { get; set; }
        public string BookName { get; set; }
        public string Level{ get; set; }

All good so far...

Next I published my webservce into IIS7 and again tested and is running. Now the fun part, i have built an ap that is supposed to call the url, parse it then add to the list view. However as soon as the activity loads i get the folowing error:

PI must not start with xml (position:unknown xm@1:5 in

This is how im calling the webservice in android:

static final String URL = "http://IP here:4657/Service.svc/GetAllBooks";
      // XML node keys
      static final String KEY_BOOKDETAILS = "BookDetails"; // parent node
      static final String KEY_BOOKID = "Bookid";
      static final String KEY_BOOKNAME = "BookName";
      static final String KEY_LEVEL= "Level";

One good thing i suppose is that the app is hitting the webservce. So is the problem with the format of the XML?
Question by:wilko100
    LVL 12

    Accepted Solution

    XML tags are case sensitive and I noticed that static final String KEY_BOOKID = "Bookid" has a small case "i" but the XML tag has a capital "I" in BookId.

    Try using:
    static final String KEY_BOOKID = "BookId";
    LVL 12

    Expert Comment

    You also might need to start your XML file with a declaration, that PI error seems to be complaining that your file starts with an XML tag. PI stands for processing instruction.

    This is an example of an XML declaration:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>

    Author Comment

    Ah yeah, ok i have amended the BookId but i still get the error. So it must be the declaration but how do i change that and is that set in the DataContract or Operationcontract code section?
    LVL 12

    Expert Comment

    I'm not too familair with DataContract or Operationcontract. If you point me to a web resource, I can read about it and get back with you.

    In the meantime, it might work if you simply open the XML file in Notepad and merely add the line, save the file, close Notepad, and run the code again. This will also help determine if that's the solution to prevent the error.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Recently Amazon announced their entry in the tablet device called the Amazon Kindle Fire. Some of you might have used an Ipad or have considered buying one. While they're similar in form and function in that they both have color displays with multit…
    This is an explanation of a simple data model to help parse a JSON feed
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now