當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。