fix Bug TDI-18747: With "tAvancedFileOutputXML" and generation mode "slow with no memory consumed" xml file generated is KO.

git-svn-id: http://talendforge.org/svn/tos/trunk@74110 f6f1c999-d317-4740-80b0-e6d1abc6f99e
This commit is contained in:
wwang
2011-12-08 10:11:28 +00:00
parent ef686a25b1
commit aec99f5c0e

View File

@@ -0,0 +1,60 @@
package routines.system;
import java.io.StringReader;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
/**
* helper for xml source
* @author Administrator
*
*/
public class XMLHelper {
private static XMLHelper instance;
private XMLReader reader;
private XMLHelper() {
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
reader = factory.newSAXParser().getXMLReader();
reader.setErrorHandler(null);
} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
public static XMLHelper getInstance() {
if(instance == null) {
instance = new XMLHelper();
}
return instance;
}
/**
* validate xml source
* return true if xml is well formed
* @param source
* @return
*/
public boolean isValid(String xml) {
try {
InputSource source = new InputSource(new StringReader(xml));
reader.parse(source);
return true;
} catch(Exception e) {
return false;
}
}
}