简体   繁体   中英

Unexpected token (position:TEXT "@1:2 in java.io.InputStreamReader@3422132)

I am new to Java and Android Studio and trying to parse XML that comes from .NET Web Services, The XML I am working looks like below

<RegisterViewModal>
  <RegList>
    <Register>
      <Availability>test</Availability>
      <Rating>0</Rating>
      <Citieslist>
        <Citieslist1>
          <Citieslist1>
            <Cityid>00000000-0000-0000-0000-000000000000</Cityid>
            <Countryid>00000000-0000-0000-0000-000000000000</Countryid>
            <Cityname>hyderabad</Cityname>
          </Citieslist1>
        </Citieslist1>
      </Citieslist>
      <CountryId>00000000-0000-0000-0000-000000000000</CountryId>
      <IsQuote>false</IsQuote>
      <IsRegisterd>false</IsRegisterd>
    </Register>
  </RegList>
</RegisterViewModal>

I have tried to change the encoding to UTF-8, still issue stays.

String  Resultxml=  ServiceCallsLayer.TerstService();
String s1 = URLDecoder.decode(Resultxml, "UTF-8");
DocumentBuilder db=DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = db.parse(new ByteArrayInputStream(s1.getBytes()));

Valid xml has to start with an XML declaration, like this one:

<?xml version="1.0" encoding="UTF-8"?>

If the result from your web service doesn't include it, it's not valid xml. But you could put it in front of your resultxml before you parse it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM