Why is Content Invalid???? 2004-04-09 - By Joey Coyle
I just can't figure out what the problem is here, but I assume it is some namespace problem.
Here is the Error, and below is the Instance Document with the Schema, and finally the Method where I validate.
[Error] Instance.xml:3:10: cvc-complex-type.2.4.a: Invalid content was found starting with element 'cwe'. One of '{"":cwe}' is expected.
$$$$$$$$$$$$$$$$$$$$$$$$$$
INSTANCE DOCUMENT
<?xml version="1.0" encoding="UTF-8"?> <TransportWrapper xmlns="http://www.foo.com/ClinicalElement" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <cwe>hello</cwe> </TransportWrapper>
$$$$$$$$$$$$$$$$$$
SCHEMA
<xs:schema targetNamespace="http://www.ihc.com/ClinicalElement" xmlns="http://www.foo.com/ClinicalElement" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="TransportWrapper" type="ClinicalElement"/>
<xs:complexType name="ClinicalElement"> <xs:sequence> <xs:element name="cwe" type="xs:string"/> </xs:sequence> </xs:complexType>
</xs:schema>
$$$$$$$$$$$$$$$$$$$$
CODE
public Document parse(String fileName) { DOMParser parser = new DOMParser(); Document doc = null;
setFeature(parser, "http://xml.org/sax/features/validation", true); setFeature(parser, "http://apache.org/xml/features/validation/schema", true); setFeature(parser, "http://apache.org/xml/features/validation/schema-full-checking", true);
try { parser.setProperty( "http://apache.org/xml/properties/schema/external-schemaLocation", "http://www.foo.com/ClinicalElement ClinicalElement.xsd"); } catch (SAXNotRecognizedException e) { System.out.print("Unrecognized property: "); System.out.println("http://apache.org/xml/properties/schema/external- schemaLocation"); } catch (SAXNotSupportedException e) { System.out.print("Unrecognized property: "); System.out.println("http://apache.org/xml/properties/schema/external- schemaLocation"); }
try { parser.parse(fileName); doc = parser.getDocument();
} catch (IOException ie) { System.out.println("Could not read file."); } catch (SAXException e) { System.out.print("Could not create Document: "); System.out.println(e.getMessage()); }
return doc; }
--------------------------------------------------------------------- To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected) For additional commands, e-mail: xerces-j-user-help@(protected)
|
|