This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes validation question od XML schemas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "validation question od XML schemas" Watch "validation question od XML schemas" New topic

validation question od XML schemas

mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
noe im trying to validate my XML with .xsd
and getting error
Parsing error: error The content of element type "memories" must match "(memory)".
<?xml version="1.0"?>
<memories xmlns:xsi="" xsi:noNamespaceSchemaLocation="http://localhost/estart/memory.xsd">
<memory tapeid="23412">
<donor>John Baker</donor>
<subject>Fishing off Pier 60</subject>
<memory tapeid="23692">
<donor>Elizabeth Davison</donor>
<subject>Beach volleyball</subject>

<xsd:schema xmlns:xsd="">
<xsd:element name="memories">
<xsd:element name="memory" type="memoryType"/>
<xsd:complexType name="memoryType">
<xsd:element name="subdate" type="xsd ate"/>
<xsd:element name="donor" type="xsd:string"/>
<xsd:element name="subject" type="xsd:string"/>
<xsd:attribute name="tapeid" type="xsd:integer" />

THe java class

public class TestXSD {

public static void main (String args[]) {
File docFile = new File("C:/XML/memory.xml");

try {
DOMParser parser = new DOMParser();
parser.setFeature("", true);


ErrorChecker errors = new ErrorChecker();

} catch (Exception e) {
System.out.print("Problem parsing the file.");

* TestXSD constructor comment.
public TestXSD() {

and the ErrorChecker method
public class ErrorChecker extends DefaultHandler
public ErrorChecker() {
public void error (SAXParseException e) {
System.out.println("Parsing error: error "+e.getMessage());
public void warning (SAXParseException e) {
System.out.println("Parsing problem: warning "+e.getMessage());
public void fatalError (SAXParseException e) {
System.out.println("Parsing error: fatalError "+e.getMessage());
System.out.println("Cannot continue.");


PLEASE HELP . Im clueless :-(
mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
i found out )
I shud have written
<xs:element name="memory" type="memoryType" minOccurs="0" maxOccurs="unbounded"/>
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
yup, if this is not mentioned, it is treated as a required element. I ran into the same thing the other day.
- madhav

Take a Minute, Donate an Hour, Change a Life
mou haj
Ranch Hand

Joined: Sep 12, 2001
Posts: 81
Hi Madhav,
Im very new to XML...
Can you tell me suppose I have an XML file and I have the XML schema .. how now ill have to extract the data and fill in a database. I mean I know ill have to parsing... but how.. can u gimme some sample code...
I agree. Here's the link:
subject: validation question od XML schemas
It's not a secret anymore!