|
Dobrý den,
řešil jsem stejný problém. XSD mám v resource, ale je možné použít i XSD z disku. Ostatní XSD leží ve stejné složce jako výchoz XSD. Java code: public static void validateXmlFile(File xmlFile) throws ParserConfigurationException, IOException, JAXBException, SAXException { //Building a Schema instance SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); Source schemaFile = new StreamSource(new File(Validator.class.getResource("/xsd/mets.xsd").getPath())); Schema schema = schemaFactory.newSchema(schemaFile); //Creating a SAXParser for our input XML //First the factory final SAXParserFactory factory = SAXParserFactory.newInstance(); //Must be namespace aware to receive element names factory.setNamespaceAware(true); //Setting the Schema for validation factory.setSchema(schema); //Now the parser itself final SAXParser parser = factory.newSAXParser(); //Creating an instance of our special handler final MyContentHandler handler = new MyContentHandler(); //Parsing parser.parse(xmlFile, handler); } V XSD mám: <xsd:schema targetNamespace="http://www.loc.gov/METS/" xmlns="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:nsesss="http://www.mvcr.cz/nsesss/v2" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xsd:import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink.xsd" /> <xsd:import namespace="http://www.mvcr.cz/nsesss/v2" schemaLocation="nsesss.xsd" /> ... S pozdravem, Korecký
| |||||||
Title: Sign
- Validace XML souboru podle XSDcka Dušan Rychnovský
- Re: Validace XML souboru podle XSDcka Vladislav Korecký
- Re: Validace XML souboru podle XSDcka Dušan Rychnovský
- Re: Validace XML souboru podle XSDcka Dušan Rychnovský
- Re: Validace XML souboru podle XSDcka Vladislav Korecký
