本文整理汇总了Java中org.jdom.input.SAXBuilder.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java SAXBuilder.setFeature方法的具体用法?Java SAXBuilder.setFeature怎么用?Java SAXBuilder.setFeature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.input.SAXBuilder
的用法示例。
在下文中一共展示了SAXBuilder.setFeature方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: constructDocumentFromXml
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Construct document from xml string.
*
* @param xmlString the xml string
* @return the document
*/
public static Document constructDocumentFromXml(final String xmlString) {
try {
final SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder
.build(new ByteArrayInputStream(xmlString.getBytes(Charset.defaultCharset())));
} catch (final Exception e) {
return null;
}
}
示例2: testConvertFull
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
@Test
public void testConvertFull() throws Exception {
SAXBuilder builder = new SAXBuilder();
builder.setValidation(false);
builder.setFeature("http://xml.org/sax/features/validation", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
InputStreamReader testIS = new InputStreamReader(ClassLoader.class.getResourceAsStream(testXML), "UTF-8");
Document document = builder.build(testIS);
Element sourceDocument = document.getRootElement();
String testText = NlmToDocumentTextConverter.getDocumentText(sourceDocument, null);
testIS.close();
InputStream expectedIS = ClassLoader.class.getResourceAsStream(testTXT);
String expectedText = IOUtils.toString(expectedIS, "UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
expectedIS.close();
assertEquals(expectedText, testText);
}
示例3: testConvertFullNestedInOAI
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
@Test
public void testConvertFullNestedInOAI() throws Exception {
SAXBuilder builder = new SAXBuilder();
builder.setValidation(false);
builder.setFeature("http://xml.org/sax/features/validation", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
InputStreamReader testIS = new InputStreamReader(ClassLoader.class.getResourceAsStream(testXmlNestedInOAI), "UTF-8");
Document document = builder.build(testIS);
Element sourceDocument = document.getRootElement();
String testText = NlmToDocumentTextConverter.getDocumentText(sourceDocument,
Namespace.getNamespace("http://www.openarchives.org/OAI/2.0/"));
testIS.close();
InputStream expectedIS = ClassLoader.class.getResourceAsStream(testTxtNestedInOAI);
String expectedText = IOUtils.toString(expectedIS, "UTF-8").replaceAll(System.getProperty("line.separator"), "\n");
expectedIS.close();
assertEquals(expectedText, testText);
}
示例4: constructDocumentFromXmlString
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public static Document constructDocumentFromXmlString(final String xmlString) {
try {
final SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://xml.org/sax/features/external-general-entities", false);
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder
.build(new ByteArrayInputStream(xmlString.getBytes()));
} catch (final Exception e) {
return null;
}
}
示例5: JPFClasspathFixProcessor
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public JPFClasspathFixProcessor()
{
super();
sax = new SAXBuilder();
sax.setValidation(false);
sax.setReuseParser(true);
sax.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
Format format = Format.getRawFormat();
format.setOmitEncoding(true);
format.setOmitDeclaration(true);
format.setLineSeparator("\n");
format.setEncoding("UTF-8");
xmlOut = new XMLOutputter(format);
}
示例6: extractText
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Extracts plain text from given xml input.
*
* @param xmlInput
* @param oaiNamespace
* @return plaintext extracted from xml input
* @throws JDOMException
* @throws IOException
*/
protected static CharSequence extractText(String xmlInput, Namespace oaiNamespace)
throws JDOMException, IOException {
SAXBuilder builder = new SAXBuilder();
builder.setValidation(false);
builder.setFeature("http://xml.org/sax/features/validation", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
builder.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
StringReader textReader = new StringReader(xmlInput);
Document document = builder.build(textReader);
Element sourceDocument = document.getRootElement();
return NlmToDocumentTextConverter.getDocumentText(sourceDocument, oaiNamespace);
}
示例7: createBuilder
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Create and initialize the SAX builder.
*
* @return the SAX builder instance.
* @since 1.4.9
*/
protected SAXBuilder createBuilder() {
final SAXBuilder builder = new SAXBuilder();
builder.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
return builder;
}