xml文件在windows环境下能正常解析,但在linux下就报错
有一个xml文件在windows环境下能正常解析,但在linux下就报错了
解析方法
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.SAXReader;
import org.dom4j.io.XMLWriter;
ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes());
SAXReader saxReader = new SAXReader();
Document document = saxReader.read(in);//报错行
Element result = document.getRootElement();
<?xml version="1.0" encoding="GB2312"?>
<workflow label="TaskAllTest" tasktype="workflow" tasktag="template.TaskAllTest2">
......
</workflow >
文件太大了就没贴了,这个文件在windows下是能正常解析的,其它好多xml文件在linux下也能正常解析,但就这一个不行,我确认这个文件是没有乱码,为正常的xml格式。
请问有人遇到这样的情况吗?
报错信息:
<May 8, 2012 4:36:03 PM CST> <Error> <com.ai.appframe2.complex.service.proxy.ProxyInvocationHandler> <BEA-000000> <方法异常
org.xml.sax.SAXParseException: <Line 1, Column 4340>: XML-20126: (Fatal Error) '<' cannot appear in attribute value.
at oracle.xml.parser.v2.XMLError.flushErrorHandler(XMLError.java:422)
at oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:287)
at oracle.xml.parser.v2.XMLReader.scanNameChars(XMLReader.java:1240)
at oracle.xml.parser.v2.XMLReader.scanQName(XMLReader.java:2069)
at oracle.xml.parser.v2.NonValidatingParser.parseAttr(NonValidatingParser.java:1733)
at oracle.xml.parser.v2.NonValidatingParser.parseAttributes(NonValidatingParser.java:1682)
at oracle.xml.parser.v2.NonValidatingParser.parseElement(NonValidatingParser.java:1523)
at oracle.xml.parser.v2.NonValidatingParser.parseRootElement(NonValidatingParser.java:409)
at oracle.xml.parser.v2.NonValidatingParser.parseDocument(NonValidatingParser.java:355)
at oracle.xml.parser.v2.XMLParser.parse(XMLParser.java:226)
at org.dom4j.io.SAXReader.read(SAXReader.java:339)
at org.dom4j.io.SAXReader.read(SAXReader.java:261)
at com.ai.appframe2.util.XmlUtil.parseXml(XmlUtil.java:24)
at com.ai.appframe2.util.XmlUtil.parseXmlOfString(XmlUtil.java:45)
------解决方案--------------------
<?xml version="1.0" encoding="GB2312"?>
把声明改成utf-8试试呢?
------解决方案--------------------
org.xml.sax.SAXParseException: <Line 1, Column 4340>: XML-20126: (Fatal Error) '<' cannot appear in attribute value.
属性值中不能出现 '<' 符号
是不是内容没有完全读进去,读到某个节点没有读结尾符 ‘>’
猜测而已...