cancel
Showing results for 
Search instead for 
Did you mean: 

Adapter Module: Validate an XML with an XSD

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

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