簡體   English   中英

如何在Java中使用xerces?

[英]how to use xerces in java?

這是我用於驗證xml的唯一代碼,我在導入org.apache.xerces時處於第2行...我下載了xerces.jar,然后將其作為外部jar從運行配置中添加到類中,您能告訴我嗎如果我正在寫,如果是,那么為什么會出現此錯誤,如果沒有,那我該怎么辦。

import java.io.File;
import org.apache.xerces.parsers.DOMParser;
public class SchemaTest {
    public static void main (String[] args) {
        File docFile = new File("C:\\Users\\ahussain\\Desktop\\Xml_Validation\\memory.xml");
        try {
            DOMParser parser = new DOMParser();
            parser.setFeature("http://xml.org/sax/features/validation", true);
            parser.setProperty("http://apache.org/xml/properties/schema/external-   noNamespaceSchemaLocation","memory.xsd");
            ErrorChecker errors = new ErrorChecker();
            parser.setErrorHandler(errors);
            parser.parse("memory.xml");
        } catch (Exception e) {
            System.out.print("Problem parsing the file.");
        }
    }
}

無需添加運行配置,而是將jar添加到您的類路徑中,

項目-BuildPath-配置構建路徑-庫-添加jar。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM