Hi all,
    I wish to elaborate more, about my XSD validation requirement (which I
believe, has a chance for implementation enhancements [wish] within Xerces)
as per this mail thread.

My XML instance document that needs to be validated, remains same (x1.xml).

My XSD document changes to following (x2.xsd),

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";>

   <xs:element name="m">
      <xs:complexType>
         <xs:sequence>
             <xs:element name="p" maxOccurs="unbounded">
                <xs:complexType>
                   <xs:sequence>
                      <xs:element name="x" type="xs:string"/>
                      <xs:element name="y" type="xs:string"/>
                   </xs:sequence>
                </xs:complexType>
             </xs:element>
         </xs:sequence>
         <xs:attribute name="id" type="xs:integer"/>
      </xs:complexType>
   </xs:element>

</xs:schema>

My java program, changes to following,

package org.w3.xsd.samples;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;

import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

public class XSDValidationSample {

public static void main(String[] args) {
try {
SchemaFactory schemaFactory = SchemaFactory.newInstance("
http://www.w3.org/XML/XMLSchema/v1.1";);
Schema schema = schemaFactory.newSchema(new
URL("file:///c:/<path>/x2.xsd"));
Validator validator = schema.newValidator();
validator.setErrorHandler(new XSValidatorErrorHandler());

StreamSource strSource = new StreamSource("file:///c:/<path>/x1.xml");
validator.validate(strSource);
}
catch (SAXException ex) {
ex.printStackTrace();
}
                catch (MalformedURLException ex) {
                ex.printStackTrace();
}
                catch (IOException ex) {
                ex.printStackTrace();
}
}
static class XSValidatorErrorHandler implements ErrorHandler {

@Override
public void error(SAXParseException spe) throws SAXException {
int lineNo = spe.getLineNumber();
int colNo = spe.getColumnNumber();
String errorMesg = spe.getMessage();
System.err.println("[Error] : (" + lineNo + ", " + colNo + ") " +
errorMesg);
}

@Override
public void fatalError(SAXParseException spe) throws SAXException {
int lineNo = spe.getLineNumber();
int colNo = spe.getColumnNumber();
String errorMesg = spe.getMessage();
System.err.println("[Fatal Error] : (" + lineNo + ", " + colNo + ") " +
errorMesg);
}

@Override
public void warning(SAXParseException spe) throws SAXException {
int lineNo = spe.getLineNumber();
int colNo = spe.getColumnNumber();
String errorMesg = spe.getMessage();
System.err.println("[Warning] : (" + lineNo + ", " + colNo + ") " +
errorMesg);
}
}
}

When I run above mentioned java program, the output appears as follows,

[Error] : (13, 9) cvc-complex-type.2.4.a: Invalid content was found
starting with element 'y1'. One of '{y}' is expected.

Now the error location line & column number values are displayed within the
output. This is what, I wish to achieve. But for this, I've to use java's
StreamSource to represent my XML instance document. And my validation root
within the XML instance document, needs to be the top most XML element node.

The XSD 1.1 structures spec, defines validation root as following,
<quote>
[Definition:]  The element or attribute information item at which
·assessment· begins is called the validation root.
</quote>

But following is what I wish to achieve,
I wish that, the validation root to be XML element "p" (and I wish to keep
my XML input document same as I've posted, i.e element "m" encapsulates
elements "p"). And the validation failure messages, should show the line
and column locations within the input XML instance document.


Any thoughts please, how can we achieve above requirements with Xerces? Wrt
the use case I've described within this thread, do we have case for
functional enhancements within Xerces?



-- 
Regards,
Mukul Gandhi

Reply via email to