在java中解析XML文件时出现错误
我在代码中使用以下类来解析 3.43MB 的巨大 XML 数据,并尝试将节点值检索到哈希表中。
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
我的代码在这里抛出错误:
String nodeValue=node.getNodeValue();
Error is:
Exception in thread "main" java.lang.StackOverflowError
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredTextImpl.synchronizeData(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.CharacterDataImpl.getNodeValue(Unknown Source)
即使它尝试像这样在控制台中打印数据:
System.out.println(node.getNodeValue());
错误是这样的:
Exception in thread "main" java.lang.StackOverflowError
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredTextImpl.synchronizeData(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.CharacterDataImpl.getNodeValue(Unknown Source)
我相信 node.getNodeValue()
无法在 XML 数据的某个点读取.
我无法摆脱这个错误。请帮我。
I am using following classes in my code to parse huge XML data of 3.43MB and trying retrieve node values into hashtable.
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
My code here is throwing error:
String nodeValue=node.getNodeValue();
Error is:
Exception in thread "main" java.lang.StackOverflowError
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredTextImpl.synchronizeData(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.CharacterDataImpl.getNodeValue(Unknown Source)
even if it try to print the data in console like this:
System.out.println(node.getNodeValue());
Error is this:
Exception in thread "main" java.lang.StackOverflowError
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl.getNodeValueString(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.DeferredTextImpl.synchronizeData(Unknown Source)
at com.sun.org.apache.xerces.internal.dom.CharacterDataImpl.getNodeValue(Unknown Source)
I believe that node.getNodeValue()
is unable to read at a certain point of XML data.
I am unable to get rid of this error. Please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你碰巧使用(无限)递归吗?
或者可能是损坏的 xml 文件? (尝试用你喜欢的浏览器打开它)
Do you happen to use (infinite) recursion?
Or maybe a corrupted xml file? (try to open it with your favorite browser)
3.4 MB 的文件并不是那么大,但是如果它包含大量嵌套术语,您使用的库可能无法处理。例如,一个 HTML 页面可能有很多不匹配的标签,这可能会导致 XML 解析器失败。
例如,
几百或几千个
就足以耗尽堆栈。A 3.4 MB file is not that big, however if it contains lots of nested terms the library you are using might not cope with that. e.g. a HTML page can have lots of unmatched tags and this could cause an XML parser to fail this way.
e.g.
A few hundred or thousand
<br>
could be enough the exhaust the stack.据我了解 Node.getNodeValue() 不会递归。它只是打印当前节点的值,它是一个字符串。这可能是数据和代码相关的错误。
发布您的代码和 XML 结构(如果不是完整的 xml)将会有所帮助。
或者,您可以尝试使用 SAX 解析器。
As for as I understand Node.getNodeValue() will not recurse through. It just prints the value of the current node which is a string. This may be data and your code dependent error.
Posting your code and XML structure (if not the complete xml) will help.
Alternatively, you can try using SAX parser.
您可能只需要使用
-XssSOMETHING
来允许更多堆栈。如果确实存在无限递归,调试器将在堆栈上一遍又一遍地向您显示相同的内容。You probably just need to use
-XssSOMETHING
to allow for more stack. If there's really an infinite recursion, the debugger will show you the same things over and over on the stack.