File tree Expand file tree Collapse file tree 3 files changed +37
-6
lines changed
main/java/org/springframework/xml/xsd/commons
java/org/springframework/xml/xsd/commons
resources/org/springframework/xml/xsd Expand file tree Collapse file tree 3 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -143,13 +143,18 @@ public void afterPropertiesSet() throws IOException {
143143 for (int i = 0 ; i < xsdResources .length ; i ++) {
144144 Resource xsdResource = xsdResources [i ];
145145 Assert .isTrue (xsdResource .exists (), xsdResource + " does not exit" );
146- XmlSchema xmlSchema = schemaCollection
147- .read (SaxUtils .createInputSource (xsdResource ), validationEventHandler );
148- xmlSchemas .add (xmlSchema );
146+ try {
147+ XmlSchema xmlSchema = schemaCollection
148+ .read (SaxUtils .createInputSource (xsdResource ), validationEventHandler );
149+ xmlSchemas .add (xmlSchema );
149150
150- if (inline ) {
151- inlineIncludes (xmlSchema , processedIncludes , processedImports );
152- findImports (xmlSchema , processedImports , processedIncludes );
151+ if (inline ) {
152+ inlineIncludes (xmlSchema , processedIncludes , processedImports );
153+ findImports (xmlSchema , processedImports , processedIncludes );
154+ }
155+ }
156+ catch (Exception ex ) {
157+ throw new CommonsXsdSchemaException ("Schema [" + xsdResource + "] could not be loaded" , ex );
153158 }
154159 }
155160 if (logger .isInfoEnabled ()) {
Original file line number Diff line number Diff line change @@ -108,4 +108,16 @@ public void testCreateValidator() throws Exception {
108108 XmlValidator validator = collection .createValidator ();
109109 assertNotNull ("No XmlValidator returned" , validator );
110110 }
111+
112+ public void testInvalidSchema () throws Exception {
113+ Resource invalid = new ClassPathResource ("invalid.xsd" , AbstractXsdSchemaTestCase .class );
114+ collection .setXsds (new Resource []{invalid });
115+ try {
116+ collection .afterPropertiesSet ();
117+ fail ("CommonsXsdSchemaException expected" );
118+ }
119+ catch (CommonsXsdSchemaException ex ) {
120+ // expected
121+ }
122+ }
111123}
Original file line number Diff line number Diff line change 1+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2+ <xsd : schema xmlns : xsd =" http://www.w3.org/2001/XMLSchema"
3+ targetNamespace =" urn:1"
4+ xmlns =" urn:1"
5+ xmlns : imported =" urn:2" elementFormDefault =" qualified" >
6+ <xsd : include schemaLocation =" X.xsd" />
7+ <!-- <xsd:import schemaLocation="D.xsd" namespace="urn:2"/>-->
8+ <xsd : complexType name =" B" >
9+ <xsd : sequence >
10+ <xsd : element type =" C" name =" c" />
11+ <xsd : element type =" imported:D" name =" d" />
12+ </xsd : sequence >
13+ </xsd : complexType >
14+ </xsd : schema >
You can’t perform that action at this time.
0 commit comments