本文整理汇总了Java中org.apache.xerces.parsers.DOMParser.setFeature方法的典型用法代码示例。如果您正苦于以下问题:Java DOMParser.setFeature方法的具体用法?Java DOMParser.setFeature怎么用?Java DOMParser.setFeature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.xerces.parsers.DOMParser
的用法示例。
在下文中一共展示了DOMParser.setFeature方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadXMLFile
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* Loads an XML file from an InputStream.
* <br>
* Note: the source stream is closed internally
*
* @param configurationFileStream the source stream
* @return the loaded XML document
* @throws IOException
* @throws SAXException
*/
public static Document loadXMLFile( InputStream configurationFileStream ) throws IOException,
SAXException {
try {
DOMParser parser = new DOMParser();
// Required settings from the DomParser
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
parser.parse(new InputSource(configurationFileStream));
return parser.getDocument();
} finally {
IoUtils.closeStream(configurationFileStream);
}
}
示例2: XMLUtils
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public XMLUtils() {
try {
// Bertoli Marco - load schema inside JAR
String externalSchemaLocation = XSDSchemaLoader.loadSchema(XSDSchemaLoader.JMVA_MODEL_DEFINITION);
//String externalSchemaLocation = "xml//JMTmodel.xsd";
parser = new DOMParser();
parser.setFeature(NAMESPACES_FEATURE_ID, true);
parser.setFeature(VALIDATION_FEATURE_ID, true);
parser.setFeature(VALIDATION_DYNAMIC_FEATURE_ID, true);
//parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, false);
//parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, true);
//parser.setProperty(EXTERNAL_SCHEMA_LOCATION_PROPERTY_ID, externalSchemaLocation);
//parser.setFeature(INCLUDE_IGNORABLE_WHITESPACE, false);
//NEW
//TODO:
parser.setProperty(EXTERNAL_SCHEMA_LOCATION_PROPERTY_ID, externalSchemaLocation);
//end NEW
//parser.setProperty(JAXP_SCHEMA_LANGUAGE,W3C_XML_SCHEMA);
parser.setErrorHandler(new ErrorCatcher());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: loadFromXmlFile
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public void loadFromXmlFile(
InputStream resourceStream,
String resourceIdentifier ) {
try {
DOMParser parser = new DOMParser();
// Required settings from the DomParser
parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", false); // otherwise
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
parser.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
parser.parse(new InputSource(resourceStream));
Document doc = parser.getDocument();
Element rootElement = doc.getDocumentElement();
//cleanup the properties
properties.clear();
//init the current element path
LinkedList<String> currentElementPath = new LinkedList<String>();
//start reading the DOM
NodeList rootElementChildren = rootElement.getChildNodes();
for (int i = 0; i < rootElementChildren.getLength(); i++) {
Node rootElementChild = rootElementChildren.item(i);
if (rootElementChild.getNodeType() == Node.ELEMENT_NODE) {
readXmlElement(currentElementPath, (Element) rootElementChild);
}
}
} catch (SAXException e) {
throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'",
e);
} catch (IOException ioe) {
throw new ConfigurationException("Error while parsing config file '" + resourceIdentifier + "'",
ioe);
}
}
示例4: XMLtree
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public XMLtree(){
parser = new DOMParser();
try {
parser.setFeature("http://apache.org/xml/features/dom/include-ignorable-whitespace",true);}
catch(org.xml.sax.SAXException e){
System.out.println("SAXException");
}
}
示例5: getParser
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* Get your non-cached DOM parser which can be configured to do schema
* based validation of the instance Document.
*
*/
public static DOMParser getParser(
String schemaLocationPropertyValue,
EntityResolver entityResolver,
boolean validate)
throws SAXNotRecognizedException, SAXNotSupportedException
{
boolean doingValidation =
(validate || (schemaLocationPropertyValue != null));
DOMParser parser = new DOMParser();
parser.setEntityResolver(entityResolver);
parser.setErrorHandler(new SaxErrorHandler());
parser.setFeature(DEFER_NODE_EXPANSION, false);
parser.setFeature(NAMESPACES_FEATURE_ID, true);
parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, doingValidation);
parser.setFeature(VALIDATION_FEATURE_ID, doingValidation);
if (schemaLocationPropertyValue != null) {
parser.setProperty(
SCHEMA_LOCATION,
schemaLocationPropertyValue.replace('\\', '/'));
}
return parser;
}
示例6: getDomHtmlNode
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
private DomHtmlNode getDomHtmlNode(InputSource inputSource) throws SAXException, IOException {
DOMParser parser = new DOMParser(new HTMLConfiguration());
parser.setFeature("http://xml.org/sax/features/namespaces", true);
parser.setFeature("http://cyberneko.org/html/features/balance-tags/ignore-outside-content", false);
parser.setFeature("http://cyberneko.org/html/features/balance-tags", true);
parser.setFeature("http://cyberneko.org/html/features/report-errors", false);
parser.setProperty("http://cyberneko.org/html/properties/names/elems", "lower");
parser.setProperty("http://cyberneko.org/html/properties/names/attrs", "lower");
parser.parse(inputSource);
return new DomHtmlNode(parser.getDocument());
}
示例7: parseDocument
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public Document parseDocument(InputSource input, boolean validate)
throws SAXException, IOException
{
DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation", validate);
parser.setEntityResolver(this);
parser.parse(input);
return parser.getDocument();
}
示例8: toDataBase
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
public static void toDataBase(InputStream inputStream, String fileName)
{
boolean validation = true;
DOMParser parser = new DOMParser();
Document doc;
try
{
//InputStream inputStream = file.getInputStream();
InputSource source = new InputSource(inputStream);
//String fileName = file.getFileName();
int indexForm = fileName.indexOf("_");
int indexDemo = fileName.indexOf("_", indexForm+1);
int indexTimeStamp = fileName.indexOf(".",indexDemo);
String formName = fileName.substring(0,indexForm);
String demographicNo = fileName.substring(indexForm+1, indexDemo);
String timeStamp = fileName.substring(indexDemo+1,indexTimeStamp);
//check if the data existed in the database already...
String sql = "SELECT * FROM " + formName + " WHERE demographic_no='"
+ demographicNo + "' AND formEdited='" + timeStamp + "'";
MiscUtils.getLogger().debug(sql);
ResultSet rs = DBHandler.GetSQL(sql);
if(!rs.first()){
rs.close();
sql = "SELECT * FROM " + formName + " WHERE demographic_no='"
+ demographicNo + "' AND ID='0'";
MiscUtils.getLogger().debug("sql: " + sql);
rs = DBHandler.GetSQL(sql, true);
rs.moveToInsertRow();
//To validate or not
parser.setFeature( "http://xml.org/sax/features/validation",validation );
parser.parse(source);
doc = parser.getDocument();
rs = toResultSet(doc, rs);
rs.insertRow();
}
rs.close();
}
catch(Exception e)
{
MiscUtils.getLogger().debug("Errors " + e);
}
}
示例9: parse
import org.apache.xerces.parsers.DOMParser; //导入方法依赖的package包/类
/**
* XML Parsing
* @param isValid - Validation 검사여부
* @return 파싱결과
* @throws ValidatorException
*/
@Override
public boolean parse(boolean isValid) throws ValidatorException {
// TODO Auto-generated method stub
try {
if ( (getXML() == null) && (getXMLFile() == null) ) {
String message = null;
if ( isValid ) {
message = "XML Validation을 체크하기 위한 XML이 필요합니다.";
} else {
message = "Well-Formed를 체크하기 위한 XML이 필요합니다.";
}
}
//파서를 생성한다. DOM 파서는 파서의 직접 생성이 가능하다.
DOMParser parser = new DOMParser();
//Validation의 실행 유무를 결정한다. isValid가 false일 경우 XML 문서가
//Well-Formed인지의 여부만 체크한다.
//true로 설정할 경우 XML 문서의 Validation을 체크한다.
// Well-formed : XML문서가 갖추어야 할 기본 조건을 잘지키는 문서
// Valid : Well-formed+DTD 조건을 추가로 지키고 있는 문
parser.setFeature("http://xml.org/sax/features/validation", isValid);
if(getSCHEMAFile() != null)
{
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation", getSCHEMAFile() );
}
//에러 메시지를 저장할 ErrorHandler를 세팅한다.
ErrorChecker errors = new ErrorChecker();
//파서에 ErrorHandler를 전달한다.
parser.setErrorHandler(errors);
//XML 문서를 파싱한다.
if (getXMLFile() != null) {
parser.parse(getXMLFile());
} else {
parser.parse(stringToInputSource());
}
Set errorReport = errors.getErrorReport();
//XML 문서 파싱시 발생된 에러가 있다면 XMLValidatorException을
//이용해서 에러 메시지를 사용자에게 전달한다.
if (errorReport.size() > 0) {
makeErrorMessage(errorReport);
return false;
} else {
return true;
}
} catch (Exception e) {
throw new ValidatorException(e.getMessage());
}
}