cancel
Showing results for 
Search instead for 
Did you mean: 

SAX parser

Former Member
0 Kudos

Hi,

i want to use SAX parser for MessageMapping. XML looks as follows:

<?xml version="1.0" encoding="UTF-8"?>
<msgInf_Invoice>
<row>
<DOCUMENT>
<?xml version="1.0" encoding="utf-8"?><INVOICE>....
</row>
</document>
<row>
<DOCUMENT>
<?xml version="1.0" encoding="utf-8"?><INVOICE>....
</row>
</document>
</msgInf_Invoice>

As you can see, I'm using JDBC adapter on sender site, and customer simply appends messages into CLOB field in DB. XML is not valid because, there are many occurrences of

<?xml version="1.0" encoding="utf-8"?>

(how many messages, so many times + one from XI at the beginning. When I try SAX parser it dumps, because of validation.

Is there any way to switch off validation in SAX parser, or perhaps is there way to change InputStream of parser to correct and then use full functionality of it?

thx

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi

Use like this

import these

import java.io.*;
import org.xml.sax.*;
import javax.xml.parsers.SAXParserFactory; 
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;

example use

SAXParserFactory factory = SAXParserFactory.newInstance();
  try {

        out = new OutputStreamWriter (System.out, "UTF8");
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse( new File(XML_FILE_NAME), new MapChange() );

  } catch (Throwable err) {
        err.printStackTrace ();
  }

Thanks

Gaurav

Former Member
0 Kudos

I figured out, problem is that XML from CLOB contains &gt; instead > and so on. Obviously SAX parser cann't understand < and &lt; in same document. OK, i can replace that but potentially there is problem with large messages, how to keep good performance? Any idea? How to do fastest string replacing in Java?

thx

prateek
Active Contributor
0 Kudos

See if this adapter module is of your interest. The implementation here is using DOM.

Regards,

Prateek

Former Member
0 Kudos

Well, I will not use DOM because of performance.

I tried something like this:

		byte[] bytes = Xml.getBytes(encoding);
			Xml = "";
			InputStream loc_in = new ByteArrayInputStream(bytes);
			saxParser.parse(loc_in, handler);

and also doesn't work. I'm trying to create XML IDOC......