cancel
Showing results for 
Search instead for 
Did you mean: 

Getting org.xml.sax.SAXNotRecognizedException in Java mapping. Help!

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts

I have written a java code for schema validating XI message.

my java code:

-


import java.io.FileInputStream;

import java.io.FileOutputStream;

import com.sap.aii.mapping.api.StreamTransformation;

import java.io.*;

import java.util.Map;

import javax.xml.parsers.*;

import org.xml.sax.*;

import org.xml.sax.helpers.*;

public class P2PValidation extends DefaultHandler implements StreamTransformation{

private Map map;

private OutputStream out;

//Constants when using XML Schema for SAX parsing.

static final String JAXP_SCHEMA_LANGUAGE =

"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =

"http://www.w3.org/2001/XMLSchema";

static final String JAXP_SCHEMA_SOURCE =

"http://java.sun.com/xml/jaxp/properties/schemaSource";

public void setParameter (Map param){

map = param;

}

public void execute (InputStream in, OutputStream out)

throws com.sap.aii.mapping.api.StreamTransformationException {

DefaultHandler handler = this;

SAXParserFactory factory = SAXParserFactory.newInstance();

// Obtain an object of class javax.xml.parsers.SAXParser,

factory.setNamespaceAware(true);

factory.setValidating(true);

try {

SAXParser saxParser = factory.newSAXParser();

// Setup the schema file

//saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

//saxParser.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));

saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");

saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", new File("IOReqMsgSchema.xsd"));

//System.out.println("Parsing");

this.out = out;

saxParser.parse(in, handler);

}

catch (Exception t){

t.printStackTrace();

}

}

private void write (String s) throws SAXException{

try{

out.write(s.getBytes()); out.flush();

}

catch (IOException e){

throw new SAXException("I/O error", e);

}

}

public void startDocument () throws SAXException{

write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");

write("<ns0:ValidInternalOrder xmlns:ns0=\"http://www.xyz.com/Gopal\">");

}

public void endDocument () throws SAXException {

write("</ns0:ValidInternalOrder>");

try { out.flush();

}

catch (IOException e) {

throw new SAXException("I/O error", e);

}

}

public void startElement (String namespaceURI, String sName, String qName, Attributes attrs)

throws SAXException {

System.out.println("sName="sName" qName="+sName);

if(sName.equals(qName))

write("<"sName">");

}

public void endElement (String namespaceURI, String sName, String qName) throws SAXException {

if(sName.equals(qName))

write("</"sName">");

}

public void characters (char buf[], int offset, int len)

throws SAXException {

String s = new String(buf, offset, len);

write (s);

}

public void error(SAXParseException se) throws SAXException {

throw se;

}

}

But when I run the code in my local machine or in Xi i am getting the error:

org.xml.sax.SAXNotRecognizedException:

at com.inqmy.lib.xml.parser.SAXParser.setProperty(SAXParser.java:111)

at com.inqmy.lib.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:51

at P2PValidation.execute(P2PValidation.java:38)

What is wrong with the properties I have set for schema validatation?

//Constants when using XML Schema for SAX parsing.

static final String JAXP_SCHEMA_LANGUAGE =

"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =

"http://www.w3.org/2001/XMLSchema";

static final String JAXP_SCHEMA_SOURCE =

"http://java.sun.com/xml/jaxp/properties/schemaSource";

Kindly help me understand how to correct this error. What are the correct values for properties?

Please help! URGENT!!!

Thanks

Gopal

Edited by: gopalkrishna baliga on Mar 4, 2008 12:45 PM

Accepted Solutions (0)

Answers (1)

Answers (1)

GabrielSagaya
Active Contributor
0 Kudos

please visit the thread

gopalkrishna_baliga
Participant
0 Kudos

Hi Gabriel,

I have already seen that link but did not get any solution yet.

Please help me!

-Gopal