Hi,

I had the same problem but I figured it out and now it works fine:
What parser do you use ?


import org.xml.sax.helpers.*;
import org.xml.sax.*;
import org.apache.xerces.parsers.SAXParser;
import org.apache.xerces.readers.*;
import javax.xml.parsers.DocumentBuilder;
import com.netcs.runtime.*;

public class MySaxParser2 extends DefaultHandler
{

    Message myMessage;
    SAXParser parser;

    //constructor
    public MySaxParser2 ()throws Exception
    {
        super();
        try {
            //pick a Parser:
            parser =

(SAXParser)Class.forName("org.apache.xerces.parsers.SAXParser").newInstance(
);
        }
        catch (Exception ex) {ex.printStackTrace();}
    }//end constructor


    public Message parseString(String s) throws SAXException {
        try {
            myMessage = new Message();
            parser.setContentHandler(this);
            parser.parse(new InputSource(new StringReader(s)));

            return myMessage;
        }
        catch (IOException e) {
            throw new SAXException(e);
        }
    }
......
----------------------------------------------------------------------------
-------------------------
Susy Pfeiffer
Development Mobile
Critical Path GmbH
Katharinenstr. 17-18
D-10711 Berlin, Germany

www: http://www.cp.net
Email: [EMAIL PROTECTED]

Tel: +49.30/89 66 0-0
Fax: +49.30/89 66 0-999
----------------------------------------------------------------------------
-------------------------

----- Original Message -----
From: "Delahaye, Martial (CAP, CMF, COFRAMI)"
<[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 04, 2001 3:38 PM
Subject: parsing an InputSource using SAX and xerces


> Hi
> I hava a problem when parsing an InputSource with SAX and Xerces.
> when I'm parsing a file by giving its name, it's working fine:
> Parser parser = ParserFactory.makeParser(parserName);
>             parser.setDocumentHandler(counter);
>             parser.setErrorHandler(counter);
>
> try {
>                 //if (validate && parser instanceof XMLReader)
>                 if ( parser instanceof XMLReader ){
>                     ((XMLReader)parser).setFeature(
> "http://xml.org/sax/features/validation";,
>                                                     validate);
>                     ((XMLReader)parser).setFeature(
> "http://xml.org/sax/features/namespaces";,
>                                                     setNameSpaces );
>                     ((XMLReader)parser).setFeature(
> "http://apache.org/xml/features/validation/schema";,
>                                                     setSchemaSupport );
>                     ((XMLReader)parser).setFeature(
> "http://apache.org/xml/features/nonvalidating/load-external-dtd";,
>                                                     setLoadExternalDTD );
>                     ((XMLReader)parser).setFeature(
> "http://apache.org/xml/features/validation/schema-full-checking";,
>
                                                    setSchemaFullSupport );
>
>                 }
>             } catch (Exception ex) {
>             }
> if (!uri.equals(""))
>               parser.parse(uri);
>
> uri is the name of the file.
> but when I try to do the same thing parsing an InputSource instead of an
> url, it is not working.
> parser.parse(new InputSource(new StringReader(myString)))

> make an error on the first tag. the error is something like:
> [Error] :3:136: Element type "FIRSTTAG" must be declared.
>
> Thanks for any help
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to