本文整理匯總了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;
}