0
我正在製作一個android應用程序女巫從Web服務獲取信息。我需要解析這個結果的解決方案:解析返回對象而不是arrayofobjects的web服務的響應
<Client xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://lmggroup.net/">
<ID>12805</ID>
<PersonalNumber>0</PersonalNumber>
<EntryDate>2013-01-28T14:39:01</EntryDate>
<FirstName>0</FirstName>
<LastName>0</LastName>
<Address>0</Address>
<Phone>06</Phone>
<Email>[email protected]</Email>
<OrganizationalUnitID>02901</OrganizationalUnitID>
<Password>aaaaaa</Password>
<IsActive>true</IsActive>
</Client>
我已經嘗試這種使用下面的代碼來解決這個問題
public static ArrayList<UserContent> getUserContentList(String response)
{
ArrayList<UserContent> result = new ArrayList<UserContent>();
if (response != null && response.equals("") == false)
{
KXmlParser xmlParser = new KXmlParser();
Document xmlDoc = new Document();
ByteArrayInputStream bin = new ByteArrayInputStream(response.getBytes());
InputStreamReader isr = new InputStreamReader(bin);
try
{
xmlParser.setInput(isr);
xmlDoc.parse(xmlParser);
Element xmlRoot = xmlDoc.getRootElement();
if(xmlRoot != null)
{
Element[] xmlChild = XmlParser.getChildren(xmlRoot);
for (int index = 0; index < xmlChild.length; ++index)
{
UserContent item = new UserContent();
Element[] contentNodes = XmlParser.getChildren(xmlChild[index]);
for (int i = 0; i < contentNodes.length; ++i)
{
if (contentNodes[i].getName().equals(StaticStrings.contentUserID))
{
item.id = contentNodes[i].getText(0);
}
else if (contentNodes[i].getName().equals(StaticStrings.contentUserPIB))
{
item.pib = contentNodes[i].getText(0);
}
else if (contentNodes[i].getName().equals(StaticStrings.contentUserPhone))
{
item.phone = contentNodes[i].getText(0);
}
else if (contentNodes[i].getName().equals(StaticStrings.contentUserMail))
{
item.email = contentNodes[i].getText(0);
}
}
result.add(item);
}
}
}
catch (IOException e)
{
Log.e(TAG, e.getMessage());
}
catch (XmlPullParserException e)
{
Log.e(TAG, e.getMessage());
}
try
{
isr.close();
}
catch (IOException e) {}
}
return result;
}
但是,當我把這種方法,我得到的所有的XML標籤,但他們的內容是空的。