-1

how to surpasss certain pattern with out reading it ? i have

so using SAX parser throwing "The processing instruction target matching "[xX][mM][lL]" is not allowed." how can i skip next xml pattern (mark(), reset()) and move current position after that ?``

1 Answers1

0

You can only use a SAX parser to read XML, and the error message you're receiving indicates that your data is not XML. Specifically, XML may only have at most one XML declaration (<?xml ... ?>), and it may only appear at the top of the file.

Before you can read this data via SAX, you'll have to repair it by fixing this problem with the XML declaration(s). You can do this manually in a text editor or programmatically by reading the file as text, not parsing it as XML via SAX because it's not XML.

For more details on how to eliminate XML declaration problems such as this, see the comprehensive answer given for this Stack Overflow question:

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Thanks for replying , how about i have concatenated xml docs in a file and want to use sax as it is very big file , after end of root element means depth 0 , can we go read ahead by marking and maching xml pattern ? and do something to skip ? Thanks this kind of requirement i cant change so trying to find a solution .. Thanks – user3342678 Oct 30 '15 at 00:11
  • 1
    Concatenated XML files do not form a new XML file. SAX only works with XML. First preprocess the file as *text*. Forget SAX until you convert your data to real XML: One root element only; zero or one XML declaration (only at the very top); all of the requirements for being [***well-formed***](http://stackoverflow.com/a/25830482/290085). – kjhughes Oct 30 '15 at 00:40