本文整理汇总了Java中org.jdom2.input.SAXBuilder.setSAXHandlerFactory方法的典型用法代码示例。如果您正苦于以下问题:Java SAXBuilder.setSAXHandlerFactory方法的具体用法?Java SAXBuilder.setSAXHandlerFactory怎么用?Java SAXBuilder.setSAXHandlerFactory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom2.input.SAXBuilder
的用法示例。
在下文中一共展示了SAXBuilder.setSAXHandlerFactory方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseStrictOrSloppyXML
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Returns an XML Document, parsed strictly if possible, or sloppily.
* Exceptions during strict parsing will be ignored.
*
* This method does NOT strip the XML declaration and add a wrapper
* tag with namespaces. That must be done beforehand.
*
* @see net.vhati.modmanager.core.EmptyAwareSAXHandlerFactory
* @see net.vhati.modmanager.core.SloppyXMLParser
*/
public static Document parseStrictOrSloppyXML(CharSequence srcSeq, String srcDescription) throws IOException, JDOMException {
Document doc;
try {
SAXBuilder strictParser = new SAXBuilder();
strictParser.setSAXHandlerFactory(new EmptyAwareSAXHandlerFactory());
doc = strictParser.build(new StringReader(srcSeq.toString()));
}
catch (JDOMParseException e) {
// Ignore the error, and do a sloppy parse instead.
try {
SloppyXMLParser sloppyParser = new SloppyXMLParser();
doc = sloppyParser.build(srcSeq);
}
catch (JDOMParseException f) {
throw new JDOMException(String.format("While processing \"%s\", strict parsing failed, then sloppy parsing failed: %s", srcDescription, f.getMessage()), f);
}
}
return doc;
}
示例2: parseStrictOrSloppyXML
import org.jdom2.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Returns an XML Document, parsed strictly if possible, or sloppily.
* Exceptions during strict parsing will be ignored.
*
* This method does NOT strip the XML declaration and add a wrapper
* tag with namespaces. That must be done beforehand.
*
* @see net.vhati.modmanager.core.EmptyAwareSAXHandlerFactory
* @see net.vhati.modmanager.core.SloppyXMLParser
*/
public static Document parseStrictOrSloppyXML( CharSequence srcSeq, String srcDescription ) throws IOException, JDOMException {
Document doc = null;
try {
SAXBuilder strictParser = new SAXBuilder();
strictParser.setSAXHandlerFactory( new EmptyAwareSAXHandlerFactory() );
doc = strictParser.build( new StringReader( srcSeq.toString() ) );
}
catch ( JDOMParseException e ) {
// Ignore the error, and do a sloppy parse instead.
try {
SloppyXMLParser sloppyParser = new SloppyXMLParser();
doc = sloppyParser.build( srcSeq );
}
catch ( JDOMParseException f ) {
throw new JDOMException( String.format( "While processing \"%s\", strict parsing failed, then sloppy parsing failed: %s", srcDescription, f.getMessage() ), f );
}
}
return doc;
}