`

[转]Element Type Must Be Followed By Either Attribute Specifications, “>”

XML 
阅读更多

今天碰到了一个很头疼的问题,自定义的一个XML文档,在eclipse中做测试的时候能够正常解析,但是一旦部署到服务器上就会出现下面的错误:

[Fatal Error] :1:1476: Element type “nodeName” must be followed by either attribute specifications, “>” or “/>”.
net.sf.json.JSONException: nu.xom.ParsingException: Element type “nodeName” must be followed by either attribute specifications, “>” or “/>”. at line 1, column 1476
at net.sf.json.xml.XMLSerializer.read(XMLSerializer.java:331)
at net.sf.json.xml.XMLSerializer.FromStream(XMLSerializer.java:391)
at net.sf.json.xml.XMLSerializer.FromFile(XMLSerializer.java:355)
……
Caused by: nu.xom.ParsingException: Element type “nodeName” must be followed by either attribute specifications, “>” or “/>”. at line 1, column 1476
at nu.xom.Builder.build(Unknown Source)
at nu.xom.Builder.build(Unknown Source)
at net.sf.json.xml.XMLSerializer.read(XMLSerializer.java:309)
… 62 more
Caused by: org.xml.sax.SAXParsingException: Element type “nodeName” must be followed by either attribute specifications, “>” or “/>”.
 从错误提示来看,是有标签没有结束,清空文件内容,一点点的添加,逐步排查,发现所有的标签都正常结束了阿。按照异常提示,一层层阅读源代码,从json-lib.jar到xom.jar,最后恍然大悟,应该直接拿

org.xml.sax.SAXParsingException: Element type “nodeName” must be followed by either attribute specifications, “>” or “/>”.

作为搜索条件,果不其然,使用这个关键字搜索的结果比net.sf.json.JSONException和nu.xom.ParsingException的结果多多了。

最后在关于dom4j解析编码的问题,org.xml.sax.SAXParseException: Invalid byte 1 of 1-byte UTF-8 sequence找到了关联答案,在二楼有人说

UTF-8编码中中文解析有问题
将编码格式改成“GB2312”后就可以正常解析了。<?xml version=”1.0″ encoding=”GB2312″?>

马上联想,这么奇怪的问题是不是也是编码问题导致的呢?最后把encoding从UTF-8修改为GB18030,问题解决。

疑问:为什么在eclipse中测试的时候没有出现问题,部署到tomcat或者weblogic都会出现这样的问题呢?

问题的根本原因找到了:并不是因为UTF-8解析中文有问题,而是因为部署到tomcat或者weblogic之后,读取文件的编码变了。在eclipse中的tomcat默认读取文件的编码为UTF-8,如果设置参数的话就是-Dfile.encoding=UTF-8,部署到tomcat或者weblogic之后,在启动tomcat或者weblogic时,会使用系统默认编码作为file.encoding,由于我们用的是中文系统,此时我推测应该是GB18030,按照GB18030的方法读取UTF-8存储的文件,肯定会出错。

所以这个问题有两种解决方法,一是设置-Dfile.encoding=UTF8参数,二是修改此处出错的代码。我决定使用第二种方法,不使用new XMLSerializer().readFromFile()的方法。而是自己以UTF-8的编码读取文件内容,然后调用new XMLSerializer().read()方法。

关于new XMLSerializer().readFromFile()在读取文件内容时,从字节流转换为字符流时并没有指定编码,此处应该是json-lib代码的Bug。

 

ps:原文地址:http://xieshaohu.wordpress.com/2011/02/12/element-type-nodename-must-be-followed-by-either-attribute-specifications-or/

分享到:
评论

相关推荐

    usb3.0 xhci

    The Extensible Host Controller Interface (xHCI) specification ... Note: In case of conflicts between the xHCI and the USB specifications, the USB specifications take precedence and must be followed

    Aerotech A3200 Training_V1.1.pdf

    electrical shock, bodily injury, or death the following precautions must be followed. 1. Disconnect electrical power before servicing equipment. 2. Disconnect electrical power before performing any ...

    BUS Hound

    drop.&lt;br&gt;&lt;br&gt;Searching&lt;br&gt;&lt;br&gt;Searching can be performed from the capture window in either the up or down direction by typing the search string in the lower left edit box followed by pressing the up ...

    【原创】【源代码】myshell:操作系统编程-自己用C语言写的Linux下的Shell

    echo &lt;comment&gt; - display &lt;comment&gt; on the display followed by a new line (multiple spaces/tabs may be reduced to a single space) help - display the user manual using the more filter pause - pause ...

    ES8316 user Guide.pdf

    The two analogue inputs LlNPUT1/2 RlNPUT1/2 can be selected by a switch, then followed by a differential gain boost with 0dB or +12dB gain. A differential input of either (LlNPUT1 - RlNPUT1) or ...

    swingx包

    and that jUnit.jar is either in that directory as well OR listed on your CLASSPATH.&lt;br&gt;&lt;br&gt;You can build SwingX by going to the command line and typing&lt;br&gt;ant&lt;br&gt;&lt;br&gt;That should be it--this will test...

    四级英语真题

    off.&lt;br&gt;B)The Edwards should cut down on their living expenses.&lt;br&gt;C)It'll be unwise for the Edwards to buy another house.&lt;br&gt;D)It's too expensive for the Edwards to live in their present house.&lt;br&gt;...

    abb 变频器canopen使用说明

    This chapter states the general safety instructions that must be followed when installing and operating the RCAN-01 CANopen Adapter module. The material in this chapter must be studied before ...

    Google C++ Style Guide(Google C++编程规范)高清PDF

    The format of the symbol name should be &lt;PROJECT&gt;_&lt;PATH&gt;_&lt;FILE&gt;_H_. To guarantee uniqueness, they should be based on the full path in a project's source tree. For example, the file foo/src/bar/baz.h...

    skyhigh.zip

    The device supports the ONFI Read Parameter Page operation, initiated by writing ECh to the Command Register, followed by an address input of 00h. The host may monitor the R/B# pin or wait for the ...

    2009 达内Unix学习笔记

    &gt; &gt;&gt; 输出重定向 。将一个命令的输出内容写入到一个文件里面。如果该文件存在, 就将该文件的内容覆盖; 如果不存在就先创建该文件, 然后再写入内容。 输出重定向,意思就是说,将原来屏幕输出变为文件输出,...

    eda-playground-readthedocs-io-en-latest.zip

    Log in. Click the Log in button (top right) Then either click on Google or Facebook or ...(Note: The code in the right Design pane is compiled first, followed by code in the left Testbench pane.)

    pink(idea自定义样式无背景图片).jar 工欲善其事必先利其器!,

    &lt;option name="ANNOTATION_ATTRIBUTE_NAME_ATTRIBUTES"&gt; &lt;value&gt; &lt;option name="FOREGROUND" value="ffd700" /&gt; &lt;/value&gt; &lt;/option&gt; &lt;option name="ANNOTATION_NAME_ATTRIBUTES"&gt; &lt;value&gt; ...

    LCTF软件备份VariSpec™ Liquid Crystal Tunable Filters

    Each command is terminated with an end-of-line terminator which can be either a carriage-return &lt;c/r&gt; or line feed &lt;l/f&gt;. For RS-232 models, the baud rate and terminator character are selected using ...

    ABCs2018_paper_156_rcnn-master_

    In this paper a CNN with two convolutional layers followed by a dropout then two fully connected layers is equipped with a feature selection algorithm. Accuracy rate of the networks with different ...

    北大ACM题目之3650字符替换

    Certain characters are reserved within URIs, and if a reserved character is part of an identifier then it must be percent-encoded by replacing it with a percent sign followed by two hexadecimal ...

    PSpiceforCircuitTheoryandElectronicDevices

    weexplainindetailtheoperational procedures for the new version of PSpice (10.5) but I include here a very quick explanation of the project management procedure that must be followed in order to carry ...

    小雨伞环境文件

    # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may ...

    Swift 2 by Example(PACKT,2016)

    We begin by introducing you to the latest features of Swift 2, further kick-starting your app development journey by building a guessing game app, followed by a memory game. It doesn’t end there, ...

Global site tag (gtag.js) - Google Analytics