简体   繁体   中英

Android: Retrieving XML results from a .NET soap Web Service

Okay, my issue today is that I am trying to return an XML result from my .NET web service. The XML is generated directly from an SQL stored procedure, and the XML looks like:

<?xml version="1.0" encoding="utf-8" ?> 
 <Details>
  <KlockleId>US0065NOVA</KlockleId> 
  <ListingPrice>54535.612830620680</ListingPrice> 
  <CurrencyCountry>US</CurrencyCountry> 
  <RealStateTax>0.000000000000</RealStateTax> 
  <CommonCharge>0.000000000000</CommonCharge> 
  <SquareFeet>4.200000000000000e+002</SquareFeet> 
  <ActivationDate>2011-04-19T16:16:46.577</ActivationDate> 
  <LotSize>0.000000000000000e+000</LotSize> 
  <YearBuilt>1969</YearBuilt> 
  <FirstName>Salmon Realty</FirstName> 
  <Phone>386 5474221</Phone> 
  <PropertyType>Condo/Co-op</PropertyType> 
  <Construction>Concrete</Construction> 
  <TotalRooms>None</TotalRooms> 
  <Bedroom>None</Bedroom> 
  <BathRoom>One</BathRoom> 
  <HalfBath>None</HalfBath> 
  <Address>600 Atlantic Ave N Unit: 1117</Address> 
  <Area>Volusia</Area> 
  <City>Daytona Beach</City> 
  <Country>United States</Country> 
  <PostalCode>32118</PostalCode> 
  <State>Florida</State> 
  <GMTOffset>0</GMTOffset> 
  <Status>Active</Status> 
  <Zooning>Residential</Zooning> 
  <PublicProperty>1</PublicProperty> 
  <DateAdded>2011-04-19T16:17:00</DateAdded> 
  <PropertyCategory>1</PropertyCategory> 
  <LoadType>2</LoadType> 
 </Details>

Now, when I use the XML Pull Parser, it comes up with an error:

05-12 21:42:02.963: WARN/System.err(1060): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@44e847a8) 


My code for the XML parser looks like:

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.util.Xml;

public class PropertyDetailsHandler {

    private ArrayList<PropertyDetails> details;
    private StringReader xmlReader;

    private final String DETAILS = "Details";
    private final String COUNTRY = "Country";
    private final String CITY = "City";

    public PropertyDetailsHandler(String xml) {
        xmlReader = new StringReader(xml);
    }

    public void parse() throws XmlPullParserException, IOException {
        XmlPullParser parser = Xml.newPullParser();
        parser.setInput(xmlReader);

        // The StockQuote that is currently being parsed
        PropertyDetails currentProperty = null;

        // The current event returned by the parser
        int eventType = parser.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
            String xmlNodeName;

            switch (eventType) {
            case XmlPullParser.START_DOCUMENT:
                details = new ArrayList<PropertyDetails>();
                break;
            case XmlPullParser.START_TAG:
                xmlNodeName = parser.getName();
                if (xmlNodeName.equalsIgnoreCase(DETAILS)) {
                    // When the  element is reached, create a new
                    // StockQuote.
                    currentProperty = new PropertyDetails();
                } else if (xmlNodeName.equalsIgnoreCase(COUNTRY)) {
                    currentProperty.setCountry(parser.nextText());
                } else if (xmlNodeName.equalsIgnoreCase(CITY)) {
                    currentProperty.setCity(parser.nextText());
                }
                break;
            case XmlPullParser.END_TAG:
                xmlNodeName = parser.getName();
                if (xmlNodeName.equalsIgnoreCase(DETAILS)) {
                    details.add(currentProperty);
                    break;
                }
            }

            eventType = parser.next();
        }
    }

    public ArrayList<PropertyDetails> getCountry() {
        return details;
    }
}

Right now I am only trying to parse the City and Country from the XML, but as you can see from the error it's not even picking up on my tags at all. So, any suggestions?

It sounds like your XMLReader instance is empty: not pulling anything in. Is the URL you're retrieving password authenticated somehow?

05-12 21:42:02.963: WARN/System.err(1060): org.xmlpull.v1.XmlPullParserException: unexpected type (position:END_DOCUMENT null@1:0 in java.io.InputStreamReader@44e847a8) 

Notice the position statement: 1:0 indicates that the error occured in character 1 of line 0 (or character 0 of line 1, I can never remember quite how they count these things from version to version).

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