Validate an XML File Against Multiple Schema Definitions

前端 未结 8 1537
囚心锁ツ
囚心锁ツ 2020-12-01 09:23

I\'m trying to validate an XML file against a number of different schemas (apologies for the contrived example):

  • a.xsd
  • b.xsd
  • c.xsd
8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 09:53

    If all XSDs belong to the same namespace then create a new XSD and import other XSDs into it. Then in java create schema with the new XSD.

    Schema schema = xmlSchemaFactory.newSchema(
        new StreamSource(this.getClass().getResourceAsStream("/path/to/all_in_one.xsd"));
    

    all_in_one.xsd :

    
    
    
        
        
        
    
    
    

提交回复
热议问题