- From: by way of <cmsmcq@acm.org>
- Date: Tue, 20 Aug 2002 08:04:35 -0600
- To: W3C XML Schema Comments list <www-xml-schema-comments@w3.org>
Hi, I encountered problems, when trying to validate xml with a schema. I used several methods as you can see in the code below. If anyone can see what's wrong with it, please tell!!! Thx, Jimmy The code (that won't work!): String xmlReceived="..."; DOMParser parser = new DOMParser(); StringReader reader = new StringReader(xmlReceived); InputSource inputSource = new InputSource(reader); try{ /* // I tried adding the schema location in the xml stream itself but never got an exception when using a bad xml // Like this: <"xsi:noNamespaceSchemaLocation='C:/.../testSchema.xsd'>" + xmlReceived+ // And also like this: "<xsi:schemaLocation=\"C:/.../testSchema.xsd\">" + xmlReceived; // Also like this: xmlReceived = ""+ "<document"+ "xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'"+ "xsi:noNamespaceSchemaLocation='C:/.../testSchema.xsd'>"+ "</document>"+ xmlReceived; // Even like this: "<?xml version=\"1.0\"?>"+ "<xml_root xmlns:xsi=\" http://www.w3.org/2001/XMLSchema-instance"+ "<http://www.w3.org/2001/XMLSchema-instance> \""+ "xsi:noNamespaceSchemaLocation=\"C:/.../testSchema.xsd\">"+ xmlReceived; */ // No I'm trying with the properties // This properties seem to work parser.setFeature("http://xml.org/sax/features/validation", true); // But schema validation doesn't parser.setFeature("http://apache.org/xml/features/validation/schema",true); // Also tested these features //parser.setFeature("http://apache.org/xml/features/validation/schema-full-c hecking",true); //parser.setFeature("http://apache.org/xml/features/validation/dynamic",true ); // Property doesn't work at all, doesn't even look for the file! parser.setProperty("http://apache.org/xml/properties/schema/external-schemaL ocation", "C:/.../testSchema.xsd"); //parser.setProperty("http://apache.org/xml/properties/schema/external-schem aLocation", "Choose whatever you want!"); // This property checks if the file exists, but it doesn't throw an exception when using a bad xml parser.setProperty("http://apache.org/xml/properties/schema/external-noNames paceSchemaLocation", "C:/.../testSchema.xsd"); parser.parse(inputSource); }catch(Exception e){ e.printStackTrace(); throw new NoSuchElementException("Parsing failed"); }
Received on Tuesday, 20 August 2002 10:07:31 UTC