0

Trying to deal with the library. I can not run a simple example. How do I download XML from Internet?

my xml file:

<Pet>
   <Name>Bobby</Name>
   <Age>8</Age>
   <NickName>Lucky</NickName>
</Pet>

my class:

@Root(name="Pet")
public class MyPet
{
    @Attribute(name="Name")
    public String name;

    @Attribute(name="Age")
    public int age;

    @Attribute(required=false, name="NickName")
    public String nickName;
}

call:

case R.id.button:
                    Reader reader = null;
                    reader = new StringReader(myURL);
                    Persister serializer = new Persister();
                    try
                    {
                        MyPet pet = serializer.read(MyPet.class, reader, false);
                        Log.v("SimpleTest", "Pet Name" + pet.name);
                    }
                    catch (Exception e)
                    {
                        Log.e("SimpleTest", e.getMessage());
                    }
                    break;

error:

11-04 10:01:21.319    1146-1146/com.example.Parsing E/SimpleTest﹕ unterminated entity ref (position:TEXT @1:53 in java.io.StringReader@41355b98)
Crawler
  • 1,988
  • 3
  • 21
  • 42
  • where is your parsing class...you need to have parser to parse xml data you download..... – Crawler Nov 04 '14 at 10:22
  • Not exactly helping you, but after some experimenting I'd advise against the Simple lib. It was slow and I couldn't parcel the model-objects (see http://stackoverflow.com/questions/17965014/how-to-put-simple-xml-serialization-model-objects-into-a-bundle). So I'd rather use the standard and much faster `XmlPullParser`: http://developer.android.com/training/basics/network-ops/xml.html – Blacklight Nov 04 '14 at 10:34
  • I use the library Jsoup in my projects. But I was advised Simple. said that it requires less code. But I even run it can not. A lot of problems – Sergey Balybin Nov 04 '14 at 10:43
  • Yes it's less code, but I ran into quite some problems using it on Android, and like I said it's slow. Writing a `XmlPullParser` once is not too difficult and much faster. Also, you can parcel your model-objects which you will probably need. – Blacklight Nov 04 '14 at 10:47
  • thanks for the advice. perhaps I'll leave jsop. I think it makes no sense to alter the sake of beauty. the more so that my code surround only a few classes – Sergey Balybin Nov 04 '14 at 10:51

0 Answers0