本文整理汇总了Java中org.jdom.input.SAXBuilder.setEntityResolver方法的典型用法代码示例。如果您正苦于以下问题:Java SAXBuilder.setEntityResolver方法的具体用法?Java SAXBuilder.setEntityResolver怎么用?Java SAXBuilder.setEntityResolver使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jdom.input.SAXBuilder
的用法示例。
在下文中一共展示了SAXBuilder.setEntityResolver方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadXml
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public static Element loadXml(File configXml) throws Exception {
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(
String publicId,
String systemId
)
throws SAXException, IOException {
return new InputSource(new CharArrayReader(new char[0]));
}
});
final Document document = saxBuilder.build(configXml);
return document.getRootElement();
}
示例2: processResource
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public void processResource( String resource, InputStream is, List<Relocator> relocators )
throws IOException
{
Document r;
try
{
SAXBuilder builder = new SAXBuilder( false );
builder.setExpandEntities( false );
if ( ignoreDtd )
{
builder.setEntityResolver( new EntityResolver()
{
public InputSource resolveEntity( String publicId, String systemId )
throws SAXException, IOException
{
return new InputSource( new StringReader( "" ) );
}
} );
}
r = builder.build( is );
}
catch ( JDOMException e )
{
throw new RuntimeException( "Error processing resource " + resource + ": " + e.getMessage(), e );
}
if ( doc == null )
{
doc = r;
}
else
{
Element root = r.getRootElement();
for ( @SuppressWarnings( "unchecked" )
Iterator<Attribute> itr = root.getAttributes().iterator(); itr.hasNext(); )
{
Attribute a = itr.next();
itr.remove();
Element mergedEl = doc.getRootElement();
Attribute mergedAtt = mergedEl.getAttribute( a.getName(), a.getNamespace() );
if ( mergedAtt == null )
{
mergedEl.setAttribute( a );
}
}
for ( @SuppressWarnings( "unchecked" )
Iterator<Content> itr = root.getChildren().iterator(); itr.hasNext(); )
{
Content n = itr.next();
itr.remove();
doc.getRootElement().addContent( n );
}
}
}
示例3: XML2JDOM
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Generates a Document from a XML input stream
*
* @param is the input xml stream
* @throws JDOMException if something goes wrong during the parsing process
* @throws IOException if something goes wrong reading stream
*/
public static void XML2JDOM(Reader is, Document doc) throws IOException, JDOMException {
Document tdoc = new Document();
SAXBuilder builder = new SAXBuilder();
builder.setExpandEntities(false);
builder.setEntityResolver(new MyResolver());
tdoc = builder.build(is);
Element root = tdoc.getRootElement();
Element new_root = (Element) root.clone();
doc.setRootElement(new_root);
}
示例4: XML2JDOM
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Generates a Document from a XML input stream
*
* @param is the input xml stream
* @throws Exception if something goes wrong during the parsing process
*/
public static void XML2JDOM(Reader is, Document doc) throws Exception {
Document tdoc = new Document();
SAXBuilder builder = new SAXBuilder();
builder.setExpandEntities(false);
builder.setEntityResolver(new MyResolver());
tdoc = builder.build(is);
Element root = tdoc.getRootElement();
Element new_root = (Element) root.clone();
doc.setRootElement(new_root);
}
示例5: loadXml
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
public static Element loadXml(File configXml) throws Exception {
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId,
String systemId)
throws SAXException, IOException {
return new InputSource(new CharArrayReader(new char[0]));
}
});
final Document document = saxBuilder.build(configXml);
return document.getRootElement();
}
示例6: parseXMLFileAsJDOMDocument
import org.jdom.input.SAXBuilder; //导入方法依赖的package包/类
/**
* Parses an XML file into a DOM document.
* @param filename the path of the file.
* @param useDTD true if the XML DTD should be used.
* @return DOM document
* @throws IOException
* @throws JDOMException
* @throws Exception if XML could not be parsed or file could not be found.
*/
public static Document parseXMLFileAsJDOMDocument(String filename, boolean useDTD) throws IOException, JDOMException {
InputStream stream = getInputStream(filename);
/* bug 2909888: read the inputstream with a specific encoding instead of the system default. */
InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
SAXBuilder saxBuilder = new SAXBuilder(useDTD);
/* [landrus, 26.11.09]: Use an entity resolver to load dtds from the classpath */
saxBuilder.setEntityResolver(new ClasspathEntityResolver());
Document result = saxBuilder.build(reader);
stream.close();
return result;
}