簡體   English   中英

針對XSD驗證格式正確的XML時出現問題

[英]Issue while Validating the well formed XML against XSD

我正在創建一個XML驗證器,該驗證器將針對特定模式驗證XML。 我當前正在使用OASIS架構來驗證針對該架構的聲明。以下是將其傳遞給SchemaFactory並創建架構對象然后未解析的xenc:EncryptedData元素(存在於導入的架構xenc-schema.xsd中)。

當我創建SchemaFactory的實例並嘗試加載架構時,它無法找到在上述架構中導入的架構:

XML is not valid because 
src-resolve: Cannot resolve the name 'xenc:EncryptedData' to a(n) 'element declaration' component.

創建架構對象應該能夠找到導入的架構時,如何在SchemaFactory上解析導入的架構? 以下是我正在編寫的代碼:

...
    System.out.println("Executing the value");
    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

    Source schemaFile = new StreamSource(new File("D:\\saml-schema-assertion-            2.0.xsd"));
    Schema schema = sf.newSchema(schemaFile);
    Validator validator = schema.newValidator();
    validator.setErrorHandler(new SAMLErrorHandler());

    validator.validate(new StreamSource(new File("D:\\Saml.xml")));
    System.out.println("XML is valid");
} catch (IOException ex) {
} catch (SAXException e) {
    System.out.println("XML is not valid because ");
    System.out.println(e.getMessage());
}

我正在尋找答案。

似乎未在您的XML文件中聲明xenc命名空間,或者至少未聲明整個元素xenc:EncryptedData 請發布您的XML文件。 我在XSD文件中看不到EncryptedData元素定義。

暫無
暫無

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

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