简体   繁体   中英

How to deal with [xX][mM][lL] in java

So I've got a program that is reading in large XML files, which contain multiple entries of data. So the database I'm using it for originally contained 40,000 separate entries written in XML file, but you can download one XML file that contains all the entries. However, because of this, the XML declaration element:-

<?xml version="1.0" encoding="UTF-8"?>

is called multiple times throughout the document, and I was wondering whether there was some way of dealing with this through the use of StAX parser.

Edit: should of said that I can't properly parse through my document and read everything as it keeps returning the error:-

Exception in thread "main" javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1062,6]
Message: The processing instruction target matching "[xX][mM][lL]" is not allowed.

because of the fact that the xml declaration is stated multiple times. Thanks

Until you eliminate the spurious <?xml ?> declaration(s), you cannot treat the file as XML because it is not well-formed . First treat it as text, either manually or programmatically, to eliminate the extra XML declarations before trying to parse it as XML.

For general information on all the ways the

The processing instruction target matching "[xX][mM][lL]" is not allowed.

error arises and remedies for addressing each way, see this answer (as suggested by Stefan).

This line is called the XML prolog:

<?xml version="1.0" encoding="UTF-8"?>

The XML prolog is optional. If it exists, it must come first in the document .

It should not repeated anywhere else in the document.

Source : XMLProlog-W3Scools

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM