破损的xml有可能解析出来吗

比如现在有这么一个xml文件



这时我可以读取出a的属性和b的属性

但是如果我把这个文件破坏了,比如把第一行删了成为


那么还有可能解析出b的属性吗?比如说用什么强力第三方的包之类,编程语言是java

[color=indigo]解析都是按着统一的 配对的形式进行解析的 所以解析时候用到的算法 也是这么弄的 一般很难解析出来破损的 再说破损的不符合schema会报错的 但是你可以自己试着编写个试验下 按照你自己的规范进行解析。[/color]

先自主修复一下~

你可以看看sax解析

解析xml的那些框架基本上都严格地解析xml,
这个得你自己来定制解析,从字符串匹配出发

sax能解析

先根据xml的格式检查 看是哪里破损了 然后自动修复 修复完后再解析

之前看过别人写的一段代码,处理html标签的,不知道xml可以不,供参考。
[code="java"]
public DocumentFragment getDocument(InputSource input) throws Exception {
DOMFragmentParser parser = new DOMFragmentParser();
try {
parser.setFeature("http://cyberneko.org/html/features/scanner/ignore-specified-charset",true);
// parser.setFeature(
// "http://apache.org/xml/features/include-comments", true);
// parser.setFeature("http://apache.org/xml/features/augmentations",
// true);
parser.setProperty("http://cyberneko.org/html/properties/names/elems","lower");
parser.setFeature("http://cyberneko.org/html/features/balance-tags/ignore-outside-content",false);
parser.setFeature("http://cyberneko.org/html/features/balance-tags/document-fragment",true);
parser.setFeature("http://cyberneko.org/html/features/report-errors", false);
parser.setFeature("http://xml.org/sax/features/namespaces", false);
XMLDocumentFilter[] filter = new XMLDocumentFilter[] { new MdrElementRemover() };
parser.setProperty("http://cyberneko.org/html/properties/filters",filter);
} catch (SAXNotRecognizedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXNotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HTMLDocumentImpl doc = new HTMLDocumentImpl();
doc.setErrorChecking(false);
DocumentFragment res = doc.createDocumentFragment();
DocumentFragment frag = doc.createDocumentFragment();
parser.parse(input, frag);
res.appendChild(frag);
try {
while (true) {
frag = doc.createDocumentFragment();
parser.parse(input, frag);
if (!frag.hasChildNodes())
break;
res.appendChild(frag);
}
} catch (Exception x) {
x.printStackTrace();
}
return res;
}
[/code]