Android XML Parsing error PImust not start with XML


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?
Who is Participating?
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";
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" ?>
wilko100Author Commented:
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?
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.