SAXBuilder 构建抛出 java.lang.StringIndexOutOfBoundsException
我正在解析这个 xml
<Root><Status>1</Status><Message>Get call Successful</Message><StatusCode></StatusCode><Item type = 'all' subtype = '0' ><subItem><rank>0</rank><name>humywe12</name><value>4500</value></subItem></Item></Root>
我正在使用此代码
SAXBuilder builder = new SAXBuilder();
Document doc = null;
xml = xml.replaceAll("\t", "");
StringReader r = new StringReader(xml);
try {
doc = builder.build(r); <-----here it throws error
} catch (IOException e) {
// e.printStackTrace();
throw e;
} catch (Exception e) {
// e.printStackTrace();
throw e;
}
return doc;
}
builder.build(r) 解析它,它会抛出异常 StringIndexOutOfBoundsException。
我做错了什么吗?
已更新 好的,我只删除了这些标签“type = 'all' subtype = '0'”,现在它没有给出 java.lang.StringIndexOutOfBoundsException。 SAXBUILDER有什么问题吗?
I am parsing this xml
<Root><Status>1</Status><Message>Get call Successful</Message><StatusCode></StatusCode><Item type = 'all' subtype = '0' ><subItem><rank>0</rank><name>humywe12</name><value>4500</value></subItem></Item></Root>
I am parsing it using this code
SAXBuilder builder = new SAXBuilder();
Document doc = null;
xml = xml.replaceAll("\t", "");
StringReader r = new StringReader(xml);
try {
doc = builder.build(r); <-----here it throws error
} catch (IOException e) {
// e.printStackTrace();
throw e;
} catch (Exception e) {
// e.printStackTrace();
throw e;
}
return doc;
}
builder.build(r) it throws exception StringIndexOutOfBoundsException.
Am I doing something wrong?
updated
ok I have removed only these tags "type = 'all' subtype = '0'" and now it is not giving java.lang.StringIndexOutOfBoundsException. Is there any problem with SAXBUILDER ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信这是一个已知的 JDom 错误。请参阅http://www.jdom.org/pipermail/jdom- interest/2000-August/001227.html
您可能想查看 jdom 的最新版本之一(适合您的应用程序)。
I believe this was a know JDom bug. See http://www.jdom.org/pipermail/jdom-interest/2000-August/001227.html
You may want to check out one of the latest versions of jdom (as fits within your application).
有人可以尝试为您识别错误,但我要做的就是从非常小的
xml
开始,然后继续添加它,直到我得到错误,然后查看数据中导致错误的原因错误。
Someone can try and identify the error for you, but what I would do is to start with very small
xml
, sayand keep adding to it till I get the error and then see what in the data caused the error.
属性名称和“=”之间或“=”和属性值之间不允许有空格。
请参阅规范。
Spaces are not allowed between the attribute name and the "=", or between the "=" and the attribute value.
See the spec.