我开发了简单的webservice
基础数学应用程序,我在其中使用XML
基础服务并用于sax parser
解析webservice
响应。
我已经使用 sax 解析器解析了XML
基础webservice
,但我的问题是当我解析它时没有得到特定tag
. 为此,我的代码如下。
private List < Object > callWebService() {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
final List < Object > list = new ArrayList < Object > ();
DefaultHandler handler = new DefaultHandler() {
boolean language = false;
boolean langid = false;
boolean langname = false;
boolean icon = false;
public void startDocument() throws SAXException {
list.clear();
}
public void endDocument() throws SAXException {}
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (qName.equalsIgnoreCase("language")) {
language = true;
objLanguage = new Language();
return;
}
if (qName.equalsIgnoreCase("langid")) {
langid = true;
return;
}
if (qName.equalsIgnoreCase("langname")) {
langname = true;
return;
}
if (qName.equalsIgnoreCase("icon")) {
icon = true;
return;
}
}
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("langid")) {
langid = false;
return;
}
if (qName.equalsIgnoreCase("langname")) {
langname = false;
return;
}
if (qName.equalsIgnoreCase("icon")) {
icon = false;
return;
}
if (qName.equalsIgnoreCase("language")) {
if (langid == false && langname == false && icon == false) {
language = false;
list.add(objLanguage);
return;
}
}
}
public void characters(char ch[], int start, int length) throws SAXException {
String theString = new String(ch, start, length);
if (langid == true) {
objLanguage.setLangId(theString);
} else if (langname == true) {
objLanguage.setLangName(theString);
} else if (icon == true) {
objLanguage.setIconImage(genHelper.convertIconImageInByteBuffer(theString));
}
}
};
parser.parse("http://mathevaluate.com/webservice/langlist.php", handler);
return list;
} catch (Exception ex) {
System.out.println("ERROR : " + ex.toString());
return null;
}
}
问题是language
名称标签,其中包含非常大的数据字符串,例如
<langname>this is the part where i can`t get the whole string of the tag so post this question</langname>
当我解析这个时,它不能得到这个标签的正确字符串值我怎么能得到这个?