xml validation error, pls help

I try to use the following way to validate my xml file with one schema.

// parse an XML document into a DOM tree

DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();

Document document = parser.parse(new File("instance.xml"));

// create a SchemaFactory capable of understanding WXS schemas

SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

// load a WXS schema, represented by a Schema instance

Source schemaFile = new StreamSource(new File("mySchema.xsd"));

Schema schema = factory.newSchema(schemaFile);

// create a Validator instance, which can be used to validate an instance document

Validator validator = schema.newValidator();

// validate the DOM tree

try {

validator.validate(new DOMSource(document));

} catch (SAXException e) {

// instance document is invalid!

}

got the error message like SAXException: http://www.w3.org/TR/xml-schema-1#cvc-type.3.1.1?

i am very confused. what can be the problem?

Thanks very much.

[1114 byte] By [wwuesta] at [2007-10-2 2:00:52]
# 1
Could you post the XML, the XSD and some extended version of the Exception?
DigCamaraa at 2007-7-15 19:42:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

<?xml version="1.0" encoding="UTF-8"?>

<dataset xmlns="xx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="xx yy.xsd">

<heading xsi:type="PW_Heading" datasetId="PW_2005-08-22_18-34-58.pts" generationDate="2005-08-22T16:35:00Z" providerId="PW"/>

<eventCommands>

<DEFINE>

<siEvent xsi:type="KRIMI_SiEventDefinition" eventId="KRIMI_0000177732121_SI" serviceId="KRIMI" programId="KRIMI_0000177732121"

startTime="2005-08-23T03:52:15Z" duration="00 00:48:54.000" title="SOKO Leipzig" comment="#SG:1" triggerType="TIMED">

</siEvent>

</DEFINE>

</eventCommands>

</dataset>

This should be output xml which can be validated.

the schema for heading and siEvent is:

<xs:complexType name="Heading" abstract="true">

<xs:attribute name="generationDate" type="xs:dateTime" use="required"/>

<xs:attribute name="datasetId" type="Token30" use="required"/>

<xs:attribute name="providerId" type="Token10" use="required"/>

</xs:complexType>

<xs:complexType name="SiEventDefinition" abstract="true">

<xs:choice>

<xs:element name="siStandard" type="SiStandardDefinition"/>

<xs:element name="siReference" type="SiReferenceDefinition"/>

<xs:element name="siTimeshift" type="SiTimeshiftDefinition"/>

</xs:choice>

<xs:attributeGroup ref="EventPropertyDefinition"/>

</xs:complexType>

now my output xml is:

<?xml version="1.0" encoding="UTF-8"?>

<dataset >

<heading datasetId="PW_2005-08-22_18-34-58.pts" generationDate="2005-08-22T16:35:00Z" providerId="PW"/>

<eventCommands>

<DEFINE>

<siEvent eventId="KRIMI_0000177732121_SI" serviceId="KRIMI" programId="KRIMI_0000177732121"

startTime="2005-08-23T03:52:15Z" duration="00 00:48:54.000" title="SOKO Leipzig" comment="#SG:1" triggerType="TIMED">

</siEvent>

</DEFINE>

</eventCommands>

</dataset>

my problem is: i dont know how to generate these attributes in dataset, and how to generate the xsi:type attribute in heading and siEvent.

Thanks in advance.

wwuesta at 2007-7-15 19:42:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3

I'm trying to understand what you're saying.

However:

What kind of attribute is <xs:attribute name="datasetId" type="Token30" use="required"/> ?

What I mean is: your xsd seems incomplete, there are some elements missing to help you diagnose your problem.

BTW: are you in Germany? If you have some trouble phrasing your questions, why don't you try to use that language (I understand it)? You'd have to check the posting rules, though.

DigCamaraa at 2007-7-15 19:42:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4

please pay attention on the schema part.

heading is abstract. i think this is my question.

because heading is abstract, it has xsi:type.

<xs:attribute name="datasetId" type="Token30" use="required"/> ? you can simply ingore.

"Abstract Elements and Types

ref26XML Schema provides a mechanism to force substitution for a particular element or type. When an element or type is declared to be "abstract", it cannot be used in an instance document. When an element is declared to be abstract, a member of that element's substitution group must appear in the instance document. When an element's corresponding type definition is declared as abstract, all instances of that element must use xsi:type to indicate a derived type that is not abstract. "

Thanks.

BTW: i like to practise my english a lot. thanks again.

wwuesta at 2007-7-15 19:42:07 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...