Exception: content is not allowed in Prolog-collection

Source: Internet
Author: User
Tags xml parser ultraedit

An error occurs during webwork verification. The message "content is not allowed in Prolog" is displayed. If an error occurs while parsing the XML file, find the corresponding file, I found that I forgot to comment out several lines of Chinese characters at the beginning. I commented out them and the problem was solved. Because I had not encountered such a problem before, I found the following information on the Internet:
Dom4j may encounter an error when reading the XML file: content is not allowed in Prolog exception cause
The XML is UTF-8 encoded. If the file is edited through ultraedit, it will be added to the UTF-8 file without BOM header, but dom4j does not recognize this BOM (dom4j1.3 ), solution: Upgrade dom4j to 1.6 to solve www.dom4j.org.
What is Bom? Http://www.unicode.org/faq/utf_bom.html#22

The Unicode specification has the concept of BOM. Bom -- byte order mark, which is a mark of the byte order. Here is a description of BOM:

There is a character named "Zero Width no-break space" in the UCS encoding, and its encoding is feff. Fffe does not exist in the UCs, so it should not appear in actual transmission. We recommend that you transmit the character "Zero Width no-break space" before transmitting the byte stream in the UCS specification ". In this way, if the receiver receives feff, it indicates that the byte stream is big-Endian; if it receives fffe, it indicates that the byte stream is little-Endian. Therefore, the character "Zero Width no-break space" is also called Bom.

The UTF-8 does not need BOM to indicate the byte order, but BOM can be used to indicate the encoding method. The UTF-8 code for the character "Zero Width no-break space" is ef bb bf. So if the receiver receives a byte stream starting with ef bb bf, it will know that this is UTF-8 encoding.

Windows uses BOM to mark the encoding of text files.

In addition, the Unicode website FAQ-BOM detailed Bom. The official natural authority is only in English, and it looks hard

========================================================== ========

I saw an article about using ant to build a Java project in eclipse. I created a project according to the instructions in the article, and created several folders including classes, DIST, Doc, Lib, and build. XML file. Build. the content of the XML file is also directly copied. Because the content is directly copied from the web page, "<" ">" is in Chinese format, So I replaced it.
However, if the project is selected, select "project", "properties", "builders", "New ...", When "ant build" is selected: the error "content is not allowed in Prolog" is returned when "Bucket file" is loaded.
I went to Google and circled it. I also learned something about it. I read a small article and thought it may be a build. xml file format error.

In SGML and XML, a document is composed of two sequential parts,
The PROLOG and the instance. You can see this in an HTML example:

1 <! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <HTML xmlns = "http://www.w3.org/1999/xhtml">
4 5 <title> the symbol grounding problem </title>
6 7 <body>
8 </body>
9
In this example, the prolog is lines 1-2, the instance begins on
Line 3. The PROLOG events des the doctype declaration, the external
Subset (called the DTD), and the internal subset (which you seldom
See but it's legal). The document instance includes des the document
Element (in this case <HTML> and all of its descendent content ).

You generally don't want to see the Prolog, And you generally don't
Want to store it. The doctype Declaration provides references
DTD, Which is instantiated as part of the process of validating
Document. You may want to store the reference (s), but you wouldn't
Want to store the DTD each time you store the document, as that
Wocould be a real waste (the DTD is often bigger than the document ).

It sounds like your well-formed and valid document isn't being
Considered as such by the XML processor. The error message indicates
That there is content (I. e., either elements or character data) in
The part of the document considered as the PROLOG. You may be missing
The last ">" on line 2 above, as that wowould normally be the beginning
Of the internal subset. If it found "You might get that error.
Sure enough, there are two "!" It is a Chinese state. If it is changed, it will be OK. Certificate -----------------------------------------------------------------------------------------------------------------------------------------------

When using ultraedit to compile a hibernate ing file, it is found that ultraedit automatically adds a special character to the beginning of the UTF-8 encoded file. This is invisible in ultraedit and can be seen in other editors. Content is not allowed in Prolog error occurs when dom4j is used to parse the file. Use another editor to remove the character and correct the error.

You should change to an XML parser. UTF-8 file headers are Unicode-standard and have been mentioned in the XML standard. Some XML parsers written in Java are poor and do not know such a file header. But all the better Resolvers know each other. For example, Apache parser.

Bytes ------------------------------------------------------------------------------------------------------------------

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.