Skip to Content
avatar image
Former Member

Adapter Module: Validate an XML with an XSD

Hello all,

I'm developing a PI adapter module (Exchange Infrastructure 3.0) for the Mail Adapter. In this module I need to get each XML attachment and then validate with an XSD schema, for this I'm using the SAX parser.

I successfully retrieved all XML attachments but when I'm trying to use the method setProperty of the SAXParser instance I'm getting an exception, bellow the code snippet.

	private static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
	private static final String SCHEMA_SOURCE   = "http://java.sun.com/xml/jaxp/properties/schemaSource";
	private static final String XML_SCHEMA      = "http://www.w3.org/2001/XMLSchema";
	
	public boolean isValid(byte[] src, AuditMessageKey amk1){
		SAXParserFactory spf = SAXParserFactory.newInstance();
		SAXParser sp = null;
		
		spf.setNamespaceAware(true);
		spf.setValidating(true);
		
		String[] schemas = new String[MAX_SCHEMAS];
		 
		schemas[0] = getClass().getResource(SCHEMA1).getFile();
		schemas[1] = getClass().getResource(SCHEMA2).getFile();
		schemas[2] = getClass().getResource(SCHEMA3).getFile();

		try {
			sp = spf.newSAXParser();
		}
		catch (Exception e){
			Audit.addAuditLogEntry(amk1, AuditLogStatus.ERROR, "MultipleAttachments: Error creating parser.");
			return false;
		}

// HERE IS THE STEP THROWING THE EXCEPTION
		try {
			sp.setProperty(SCHEMA_LANGUAGE, XML_SCHEMA);
		}
		catch (Exception e){
			Audit.addAuditLogEntry(amk1, AuditLogStatus.ERROR, "MultipleAttachments: Error setting schema.");
			return false;
		}		

Did Anyone have faced this issue? How can I solve this?

Best regards,

David

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • avatar image
    Former Member
    Oct 15, 2009 at 05:24 PM

    Hi David,

    we developed a xsd validation with java mapping.

    SAP has it's own parser. At the time we developed there was a bad bug in this parser. The parser throwed a fatal error although the xml was valid!

    SAP corrected the error. But this is over 1,5 years ago. I recommend a OSS .

    Regards Mario

    Add comment
    10|10000 characters needed characters exceeded