当前位置: 首页>>代码示例>>Java>>正文


Java SAXBuilder.setSAXHandlerFactory方法代码示例

本文整理汇总了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;
}
 
开发者ID:Niels-NTG,项目名称:FTLAV,代码行数:33,代码来源:TextUtilities.java

示例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;
}
 
开发者ID:Vhati,项目名称:Slipstream-Mod-Manager,代码行数:33,代码来源:ModUtilities.java


注:本文中的org.jdom2.input.SAXBuilder.setSAXHandlerFactory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。