Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Exception when using SAXParser

1 view
Skip to first unread message

Remesh Job

unread,
Mar 23, 2002, 2:03:15 AM3/23/02
to
Hi All ,

I am trying to parse XML using SAX . After getting an instance of
SAXParser, I am trying to parse using

parser.parse( uri , new MyHandler() );

where uri - filename in URI form .

But I am getting the exception

org.xml.sax.SAXParseException: The processing instruction must begin
with the name of the target.
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1171)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at SAXTest.<init>(SAXTest.java:24)
at SAXTest.main(SAXTest.java:14)
Exception in thread "main"

Can anybody tell me what could be the problem . The code is given
below

Thanks in advance
Remesh


--------------------code-------------------------------

import java.io.* ;
import javax.xml.parsers.*;
import org.xml.sax.*;

public class SAXTest
{
public static void main( String[] args ) throws Exception
{
String fileName = "d:\\brett\\test1.xml" ;
String path = new File( fileName ).toURL().toString() ;

System.out.println( path );

SAXTest st = new SAXTest( path ) ;

}

public SAXTest( String uri ) throws Exception
{
SAXParserFactory spf = SAXParserFactory.newInstance() ;
spf.setValidating(true);
SAXParser parser = spf.newSAXParser();

parser.parse( uri , new MyHandler() );
}


class MyHandler extends HandlerBase
{
}

}

Alexander Schröder

unread,
Mar 23, 2002, 3:10:43 AM3/23/02
to
> But I am getting the exception
>
> org.xml.sax.SAXParseException: The processing instruction must begin
> with the name of the target.
> at
> org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1171)
> at javax.xml.parsers.SAXParser.parse(Unknown Source) at
> javax.xml.parsers.SAXParser.parse(Unknown Source) at
> SAXTest.<init>(SAXTest.java:24)
> at SAXTest.main(SAXTest.java:14)
> Exception in thread "main"
>
> Can anybody tell me what could be the problem . The code is given below
>
Its not the code, its the XML file ... perhaps it does not start
with <?xml ... but with <? xml or something like that.

Cheers

Alex

0 new messages