Results 1 to 3 of 3
  1. #1
    DerekRaimann is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default How to resolve entities in a SAX parser - please help

    I am using the following code to create a SAX parser. My only problem is that I don't know how to assign an entity resolver to it. I know how to create an EntityResolver class with the resolveEntity method, but I don't know how to apply it to the parser, as SAXParser objects do not have a setEntityResolver method like the DocumentBuilder class does.

    Here is the code:

    Java Code:
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(false);
    SAXParser saxParser = factory.newSAXParser();
    InputStream in = new URL(url).openStream();
    saxParser.parse(new File("c:\\java\\corejava2\\Chapter2\\SAXTest\\test.xhtml"), handler);
    So how would I go about setting an EntityResolver to the saxParser object?

    Thanks for your help, I greatly appreciate it!

    -Derek

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,050
    Blog Entries
    7
    Rep Power
    23

    Default

    Quote Originally Posted by DerekRaimann View Post
    I am using the following code to create a SAX parser. My only problem is that I don't know how to assign an entity resolver to it. I know how to create an EntityResolver class with the resolveEntity method, but I don't know how to apply it to the parser, as SAXParser objects do not have a setEntityResolver method like the DocumentBuilder class does.

    Here is the code:

    Java Code:
    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setNamespaceAware(true);
    factory.setValidating(false);
    SAXParser saxParser = factory.newSAXParser();
    InputStream in = new URL(url).openStream();
    saxParser.parse(new File("c:\\java\\corejava2\\Chapter2\\SAXTest\\test.xhtml"), handler);
    So how would I go about setting an EntityResolver to the saxParser object?
    The handler you're passing to the parse( ... ) method is an EntityResolver. You can also wrap your SAX1 parser in a ParserAdapter which makes it a SAX2 parser; the latter allows you to set an EntityResolver. See the API documentation for these classes and interfaces.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    DerekRaimann is offline Member
    Join Date
    Dec 2010
    Posts
    45
    Rep Power
    0

    Default

    Thank you so much for your help regarding that matter, the problem was completely resolved after wrapping the SAXParser as a ParserAdapter object!

    -Derek

Similar Threads

  1. how to resolve this error???
    By 10e5x in forum New To Java
    Replies: 1
    Last Post: 01-21-2011, 08:40 AM
  2. Replies: 5
    Last Post: 02-25-2010, 03:06 PM
  3. EntityManager.refresh() - Works on Detatched Or Managed Entities ?
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 12-07-2009, 04:34 AM
  4. EntityManager.refresh() works only on managed entities.
    By CatchSandeepVaid in forum Enterprise JavaBeans (EJB)
    Replies: 2
    Last Post: 12-05-2009, 01:11 PM
  5. Yet another Cannot Resolve Symbol
    By Gabinka in forum New To Java
    Replies: 5
    Last Post: 03-27-2009, 11:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •