解析器错误
我想解析这个 xml 并获取标签之间的结果...但我无法获取结果我的 xml 是
处理程序
public class MyXmlContentHandler extends DefaultHandler {
String result;
private String currentNode;
private String currentValue = null;
public String getFavicon() {
return result;
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equalsIgnoreCase("result")) {
//offerList = new BFOfferList();
this.result = new String();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("result")) {
result = localName;
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
String value = new String(ch, start, length);
if (currentNode.equals("result")){
result = value;
return;
}
}
}
需要任何更改
I want to parse this xml and get the result between the tag... but i cant get the result my xml is
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><loginResponse xmlns="https://comm1.get.com/"><loginResult>true</loginResult><result>success</result></loginResponse></soap:Body></soap:Envelope>
The handler
public class MyXmlContentHandler extends DefaultHandler {
String result;
private String currentNode;
private String currentValue = null;
public String getFavicon() {
return result;
}
@Override
public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
if (localName.equalsIgnoreCase("result")) {
//offerList = new BFOfferList();
this.result = new String();
}
}
@Override
public void endElement(String uri, String localName, String qName)
throws SAXException {
if (localName.equalsIgnoreCase("result")) {
result = localName;
}
}
@Override
public void characters(char[] ch, int start, int length)
throws SAXException {
String value = new String(ch, start, length);
if (currentNode.equals("result")){
result = value;
return;
}
}
}
Any changes needed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您找到要查找的开始标记时,将调用一次或多次“字符”。您必须收集数据而不是覆盖它。更改
为
或使用 StringBuilder 来完成。此外,您应该删除它,它似乎会覆盖您的结果字符串:
编辑:
When you found the start tag you are looking for, "characters" is called one or more times. You have to collect the data not overwrite it. Change
to
Or use StringBuilder to do it. Furthermore, you should remove this, it seems to overwrite your result String:
EDIT: