今天尝试用Jsoup解析一个XML文件,其中遇到<Source>这个节点解析有问题,源文件如下:
<MeasureGroup>
<ID>土地拓展目标</ID>
<Name>土地拓展目标</Name>
<Measures>
<Measure>
<ID>ZCQTZXMGSMB</ID>
<Name>_中长期拓展项目个数目标</Name>
<DataType>BigInt</DataType>
<Source>
<DataType>BigInt</DataType>
<Source xsi:type="MeasureBinding">
<MeasureID>ZCQTZXMGSMB</MeasureID>
</Source>
</Source>
<Visible>false</Visible>
</Measure>
……
想通过debug模式找原因,又嫌麻烦,我把Source改名字又没问题了,于是直接猜测Source可能是做了特殊处理,便直接搜索源代码,找到"Source"的位置,一共有两处比较特殊:
1 jsoup-1.8.1-sources\org\jsoup\parser\Tag.java
private static final String[] inlineTags = {
"object", "base", "font", "tt", "i", "b", "u", "big", "small", "em", "strong", "dfn", "code", "samp", "kbd",
"var", "cite", "abbr", "time", "acronym", "mark", "ruby", "rt", "rp", "a", "img", "br", "wbr", "map", "q",
"sub", "sup", "bdo", "iframe", "embed", "span", "input", "select", "textarea", "label", "button", "optgroup",
"option", "legend", "datalist", "keygen", "output", "progress", "meter", "area", "param", "source", "track",
"summary", "command", "device", "area", "basefont", "bgsound", "menuitem", "param", "source", "track",
"data", "bdi", "s"
};
这里重复出现了,屏蔽掉。但是问题仍然存在
2 jsoup-1.8.1-sources\org\jsoup\parser\HtmlTreeBuilderState.java
private static final String[] InBodyStartMedia = new String[]{"param", "source", "track"};
把里面的值屏蔽,编译重新打包,引用,问题解决了!