简体   繁体   English

Digester:元素类型“user”必须由匹配的结束标签“”终止

[英]Digester: The element type “user” must be terminated by the matching end-tag “</user>”

I'm using Digester to parse a xml file and I get the following error:我正在使用 Digester 解析 xml 文件,我收到以下错误:

May 3, 2011 6:41:25 PM org.apache.commons.digester.Digester fatalError
SEVERE: Parse Fatal Error at line 2336608 column 3: The element type "user" must be terminated by the matching end-tag "</user>".
org.xml.sax.SAXParseException: The element type "user" must be terminated by the matching end-tag "</user>".

However 2336608 is the last line of my text file.但是 2336608 是我的文本文件的最后一行。 I guess I'm opening a tag and I never close it.我想我正在打开一个标签,但我从不关闭它。 Do you know how can I find it and fix it, in big text files?您知道如何在大文本文件中找到并修复它吗?

thanks谢谢

Write another script which scans each file of the line and whenever it finds an open <user> tag, increments a counter and prints编写另一个脚本,扫描该行的每个文件,每当找到打开的<user>标记时,增加一个计数器并打印

line number 1234 <user> opened (1 open total)

and whenever it finds a close </user> tag, decrements the counter prints并且每当它找到一个关闭的</user>标记时,都会减少计数器打印

line number 4546 </user> closed (0 open total)

Since you have one more opening tag than closing tag, the final output of this script will tell you that 1 tag was left open.由于您的开始标签比结束标签多一个,因此该脚本的最终 output 将告诉您有 1 个标签处于打开状态。 However, assuming that your XML model does not allow for nested <user> tags, then you can assume the problemsome declaration is wherever you see the output of line number... <user> opened (2 open total) .但是,假设您的 XML model 不允许嵌套<user>标记,那么您可以假设有问题的声明出现在您看到 output line number... <user> opened (2 open total)

Use tidy -xml -e <your-xml-file> .使用tidy -xml -e <your-xml-file> http://tidy.sourceforge.net/ http://tidy.sourceforge.net/

Tidy is a great little tool for validating HTML, and in XML mode ( -xml above) it will validate XML as well. Tidy 是一个很棒的小工具,用于验证 HTML,在 XML 模式下(上面的-xml )它也将验证 XML。

It prints out line and column numbers for parse errors.它打印出解析错误的行号和列号。

Most of the major package managers (apt, port, etc.) will have pre-built packages for it.大多数主要的 package 管理器(apt、port 等)都将为其预先构建软件包。

$ grep -Hin "</\?user>" Text.xml will print out every line with either or. $ grep -Hin "</\?user>" Text.xml将使用 or 打印出每一行。 If they're not nested, then you should be able to inspect that output fand find the missing close tag (when immediately follows. A script do do the same:如果它们没有嵌套,那么您应该能够检查 output 并找到丢失的关闭标签(紧随其后。脚本也会这样做:

https://gist.github.com/953837 https://gist.github.com/953837

This assumes that the open and close tags are on different lines.这假设打开和关闭标签位于不同的行上。

I think there is no need to start scripting for detecting xml errors.我认为没有必要开始编写脚本来检测 xml 错误。 You can use the w3 xml validator for instance http://www.w3schools.com/xml/xml_validator.asp您可以使用 w3 xml 验证器,例如http://www.w3schools.com/xml/xml_validator.asp

I just pasted a 15 mb xml in there and I managed to fix it quite easily.我刚刚在其中粘贴了一个 15 mb xml 并且我设法很容易地修复它。 You can also input the xml as a url if you have the possibility to upload it somewhere.如果您有可能将其上传到某处,您也可以将 xml 输入为 url。 Java reported the error in some place which seemed fine, but this tool localized the actual error, and after correcting that, java didn't error anymore. Java 在某些地方报告了错误,看起来还不错,但是这个工具定位了实际错误,并且在更正之后,java 不再出错。

There are many types of xml errors, and are not all related to the nested structure, so it is best to just use a well known tool for this. xml 错误有很多种类型,而且并不都与嵌套结构有关,因此最好只使用众所周知的工具。 For instance, my error was an argument error(I was missing a ") but java detected a nesting problem.例如,我的错误是参数错误(我缺少一个“),但 java 检测到嵌套问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 元素类型“主机”必须以匹配的结束标记“ </Host> ” - The element type “Host” must be terminated by the matching end-tag “</Host>” 元素类型“META”必须以匹配的结束标签“</META> ” - The element type “META” must be terminated by the matching end-tag “</META>” SaxParseException 元素类型“hr”必须由匹配的结束标记“终止</hr> “。在使用 jaxb 读取 xml 时 - SaxParseException The element type "hr" must be terminated by the matching end-tag "</hr>". while reading xml with jaxb 无效的 XML:第 6 行错误:元素类型“hr”必须由匹配的结束标记“终止”</hr> ” - Invalid XML: Error on line 6: The element type “hr” must be terminated by the matching end-tag “</hr>” XMLStreamException:[row,col]:[5,3]处的ParseError消息:元素类型“ meta”必须由匹配的结束标记“ </meta> ” - XMLStreamException: ParseError at [row,col]:[5,3] Message: The element type “meta” must be terminated by the matching end-tag “</meta>” Pom.xml:元素类型“dependencies”必须由匹配的end-tag“”终止 - Pom.xml: The element type “dependencies” must be terminated by the matching end-tag “</dependencies>” maven web.xml 元素类型“web-app”必须由匹配的结束标记“”终止 - maven web.xml The element type "web-app" must be terminated by the matching end-tag "</web- app>" 元素类型“ META”必须以匹配的结束标记“ </META> ”。 使用XSL从XML文件生成PDF时 - The element type “META” must be terminated by the matching end-tag “</META>”. while generating PDF from XML file using XSL “清单”必须以匹配的结束标签“ </manifest> ” - “manifest” must be terminated by the matching end-tag “</manifest>” 无法解析配置:hibernate.cfg.xml:元素类型“ session-factory”必须由匹配的结束标记“ </session-factory> ” - Could not parse configuration: hibernate.cfg.xml: The element type “session-factory” must be terminated by the matching end-tag “</session-factory>”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM