1
votes

how to reference XSD Schema location while parsing XML via SAX Xerces?

< ?xml version="1.0" encoding="ISO-8859-1"?> < com.firma xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

>  
< !--  xsi:noNamespaceSchemaLocation="F:\...\myschema_v2.5.xsd"   

Must I reference this element really within the XML Doc??? I hope, not... -- >

I also set it as follows in Java code, which is not elegant, while schema location is fixed(not appropriate for production)
SaxParser.setProperty( "http://java.sun.com/xml/jaxp/properties/schemaSource", "F:...\myschema_v2.5.xsd" );

2

2 Answers

1
votes

include the schema in your jar and load it using getResourceAsStream in the following way

reader.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", 
  new InputSource(getClass().getResourceAsStream(xsdLocation)));
0
votes

I got it.

one must use as follows, giving "/com/firma/project/.../myschema_v2.5.xsd" as parameter. not forgetting the "/" in the path at the very beginning.