楼主,不是偶说你,严格意义来说,你在扯蛋。
你搞的there is apple&这根本就不符合xml规范,没有人能帮助你搞定的,能搞定的也是胡扯的。
正当的途径是把偶对你说的话给提供这些内容的人,照样搬过去,骂他一顿,然后,让他改成there is <an> apple&
然后他就抬着头看着你说,实在不好意思,是我错了!
然后你就扬眉吐气的省事了。
当然@GodByeWord 说的也是正途,其他说正则表达啥的,表面看解决了,实际上是害人害已(用错误的手段来解决别人错误的问题引入),不可取。
比如下面的代码示例
public static void main(String[] args) {
XmlNode node=new XmlStringParser().parse("there is <an> apple&").getRoot();
System.out.println(node.getContent());
}
运行结果:
there is apple&
用@GodByeWord 的方法,如下:
public static void main(String[] args) {
XmlNode node=new XmlStringParser().parse(" apple& ]]>").getRoot();
System.out.println(node.getContent());
} 运行结果如下:
there is apple&
当然,偶的解析器太强,即使是there is apple&的方式,它也不会报错,也不会异常,当然,也不会出来你期望的结果:
public static void main(String[] args) {
XmlStringParser parser = new XmlStringParser();
XmlNode node=parser.parse("there is apple&").getRoot();
System.out.println(node);
}
运行结果:
there isapple&
它“聪明”的认为,你的忘记写结束标签了,另外它也认为你忘记把”&“替换为"&"了,于是它就给你自动”纠正“了,呵呵