IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  XML Validation using SAX Parser

    Posted Thu April 08, 2004 01:37 PM

    Hi,

    I am trying to parse an XML using the SAX parser.
    But when i run it i get File “DTD File Name” not found.

    public static void validateUsingSAX(String xmldata) {
    try {
    InputStream is = new ByteArrayInputStream(xmldata.getBytes());
    SAXParserFactory f = SAXParserFactory.newInstance();
    f.setValidating(true);
    SAXParser p = f.newSAXParser();
    DefaultHandler h = new MyErrorHandler();
    p.parse(is,h);
    } catch (Exception e) {
    errorMessage = errorMessage + " Message==> " + e.getMessage()+ “\n”;
    }
    }

    private static class MyErrorHandler extends DefaultHandler {

    public void warning(SAXParseException e) throws SAXException {
    createErrorMessage(e);
    }
    public void error(SAXParseException e) throws SAXException {
    createErrorMessage(e);
    }
    public void fatalError(SAXParseException e) throws SAXException {
    createErrorMessage(e);
    }

    private void createErrorMessage(SAXParseException e) {
    errorMessage = errorMessage + " Line number:" + e.getLineNumber() + " Message==> " + e.getMessage() + “\n”;
    }
    }

    Thanks in advance,

    Gamad


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: XML Validation using SAX Parser

    Posted Sat April 10, 2004 08:12 AM

    Does your xml file contain valid directory path to the DTD or XSD file?
    By the way, there are multiple validation build-in services in webMethods. What is the reason for java validation? just for the SAX parser?


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 3.  RE: XML Validation using SAX Parser

    Posted Tue April 13, 2004 08:59 PM

    Hi Terry,

    Here is a snippet of the xml that i am trying to validate

    !DOCTYPE meeting_display SYSTEM “file:test1234.dtd”>

    Note. leading < is removed since the formatting was getting messed.

    I agree there are a few methods in webMethods that help you to validate. But whenevever there is a change in DTD i have to change the RECORD against which i am validating or the schema that i am validating against. But if i use a java code that uses a parser like SAX, all i have to do is move the modified DTD to the appropriate place.

    Gamad


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 4.  RE: XML Validation using SAX Parser

    Posted Fri April 16, 2004 03:50 PM

    I see where you are getting at. Firstly, the example you are given is not a well-formed xml which should never made it to validation. Even it did, webMethods pharser could still pick up the error. I think if I understand you correctly, its a matter of convienence in the event of schema changing. From what I understand, schema should not be change often after production, even if it did, it should just be an easy delete then import procedure. By creating your own pharser might create a maintance and debuging issue in the future. Maybe just a little over-killed.

    cheers


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services