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:
好的,我今天的问题是我试图从.NET Web服务返回XML结果。 XML直接从SQL存储过程生成,XML看起来像:
<?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:
现在,当我使用XML Pull Parser时,它会出现错误:
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:
我的XML解析器代码如下所示:
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?
现在我只是试图从XML解析城市和乡村,但正如你从错误中看到的那样,它根本就没有拿起我的标签。那么,有什么建议吗?
1 个解决方案
#1
0
It sounds like your XMLReader instance is empty: not pulling anything in. Is the URL you're retrieving password authenticated somehow?
听起来你的XMLReader实例是空的:没有任何内容。你正在检索密码的URL是否以某种方式进行了身份验证?
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).
注意位置声明:1:0表示错误发生在第0行的第1个字符(或第1行的第0个字符,我永远不会记得他们如何从版本到版本计算这些东西)。
#1
0
It sounds like your XMLReader instance is empty: not pulling anything in. Is the URL you're retrieving password authenticated somehow?
听起来你的XMLReader实例是空的:没有任何内容。你正在检索密码的URL是否以某种方式进行了身份验证?
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).
注意位置声明:1:0表示错误发生在第0行的第1个字符(或第1行的第0个字符,我永远不会记得他们如何从版本到版本计算这些东西)。