[ 
https://issues.apache.org/jira/browse/XERCESJ-1387?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Michael Glavassevich resolved XERCESJ-1387.
-------------------------------------------

    Resolution: Invalid

You're not getting PSVI because you're starting validation from an element 
which doesn't have a global element declaration in the schema.  The only global 
element declaration in your schema is "root" and so that is the only valid 
element that you can pass in as an element node to validate().  If the error 
handler in your test didn't ignore errors you would see that:

org.xml.sax.SAXParseException: cvc-elt.1.a: Cannot find the declaration of 
element 'item'.
        at 
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:196)
        at 
org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:132)
        at 
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:394)
        at 
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:325)
        at 
org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:282)
        at 
org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:2126)
        at 
org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:787)
        at 
org.apache.xerces.jaxp.validation.DOMValidatorHelper.beginNode(DOMValidatorHelper.java:276)
        at 
org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:242)
        at 
org.apache.xerces.jaxp.validation.DOMValidatorHelper.validate(DOMValidatorHelper.java:187)
        at 
org.apache.xerces.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:115)
        at ValidationTest.addItemNode(ValidationTest.java:137)

If you want to start validation from other parts in the document you would need 
to modify your schema so that the other element declarations are also global.
        at ValidationTest.doTest(ValidationTest.java:81)

> Validation of elements does not add a PSVI data
> -----------------------------------------------
>
>                 Key: XERCESJ-1387
>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1387
>             Project: Xerces2-J
>          Issue Type: Bug
>          Components: JAXP (javax.xml.validation), XML Schema API
>    Affects Versions: 2.9.1
>         Environment: Java 1.6.0_10 Windows Vista Business
>            Reporter: Stefan Chodnik
>            Assignee: Michael Glavassevich
>
> Test code:
> import java.io.File;
> import java.io.IOException;
> import javax.xml.transform.dom.DOMResult;
> import javax.xml.transform.dom.DOMSource;
> import javax.xml.validation.Schema;
> import javax.xml.validation.SchemaFactory;
> import javax.xml.validation.Validator;
> import org.apache.xerces.xs.ElementPSVI;
> import org.apache.xerces.xs.XSElementDeclaration;
> import org.w3c.dom.DOMImplementation;
> import org.w3c.dom.Document;
> import org.w3c.dom.Element;
> import org.w3c.dom.bootstrap.DOMImplementationRegistry;
> import org.xml.sax.ErrorHandler;
> import org.xml.sax.SAXException;
> import org.xml.sax.SAXParseException;
> class ValidationTest {
>       public static final String namespace = "http://www.example.org/schema/";;
>       private Schema schema;
>       private Document document;
>       private Validator validator;
>       private Element item;
>       private Element foo;
>       public static void main(String[] args) {
>               System.out.println("ValidationTest start");
>               ValidationTest testClass = new ValidationTest();
>               testClass.doTest();
>       }
>       private void doTest() {
>               createSchema();
>               buildDocument();
>               try {
>                       validator.validate(new DOMSource(document), new 
> DOMResult(document));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               addItemNode();
>               addFooNode();
>               
>       }
>       
>       private void addFooNode() {
>               foo = document.createElementNS(namespace, "foo");
>               item.appendChild(foo);
>               ElementPSVI elementPSVI;
>               try {
>                       validator.validate(new DOMSource(foo), new 
> DOMResult(foo));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               elementPSVI=(ElementPSVI) foo;
>               XSElementDeclaration declaration = 
> elementPSVI.getElementDeclaration();
>               if(declaration==null){
>                       System.out.println("declaration==null //3");
>               }
>               
>               
>               try {
>                       validator.validate(new DOMSource(item), new 
> DOMResult(item));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               elementPSVI=(ElementPSVI) foo;
>               declaration = elementPSVI.getElementDeclaration();
>               if(declaration==null){
>                       System.out.println("declaration==null //4");
>               }
>               
>               try {
>                       validator.validate(new 
> DOMSource(document.getDocumentElement()), new 
> DOMResult(document.getDocumentElement()));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               elementPSVI=(ElementPSVI) foo;
>               declaration = elementPSVI.getElementDeclaration();
>               if(declaration==null){
>                       System.out.println("declaration==null //5");
>               }
>               
>       }
>       private void addItemNode() {
>               item = document.createElementNS(namespace, "item");
>               document.getDocumentElement().appendChild(item);
>               ElementPSVI elementPSVI;
>               try {
>                       validator.validate(new DOMSource(item), new 
> DOMResult(item));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               elementPSVI=(ElementPSVI) item;
>               XSElementDeclaration declaration = 
> elementPSVI.getElementDeclaration();
>               if(declaration==null){
>                       System.out.println("declaration==null //1");
>               }
>               
>               try {
>                       validator.validate(new 
> DOMSource(document.getDocumentElement()), new 
> DOMResult(document.getDocumentElement()));
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               } catch (IOException e) {
>                       e.printStackTrace();
>               }
>               elementPSVI=(ElementPSVI) item;
>               declaration = elementPSVI.getElementDeclaration();
>               if(declaration==null){
>                       System.out.println("declaration==null //2");
>               }
>               
>       }
>       private void createSchema() {
>               SchemaFactory factory = SchemaFactory
>                               
> .newInstance("http://www.w3.org/2001/XMLSchema";);
>               try {
>                       schema = factory.newSchema(new File("schema.xsd"));
>                       validator = schema.newValidator();
>                       validator.setErrorHandler(new ErrorHandler() {
>                               @Override
>                               public void error(SAXParseException exception) 
> throws SAXException {
>                               }
>                               @Override
>                               public void fatalError(SAXParseException 
> exception)
>                                               throws SAXException {
>                               }
>                               @Override
>                               public void warning(SAXParseException exception)
>                                               throws SAXException {
>                               }
>                       });
>               } catch (SAXException e) {
>                       e.printStackTrace();
>               }
>       }
>       private void buildDocument() {
>               System.setProperty(DOMImplementationRegistry.PROPERTY,
>                               
> "org.apache.xerces.dom.DOMXSImplementationSourceImpl");
>               DOMImplementationRegistry registry;
>               try {
>                       registry = DOMImplementationRegistry.newInstance();
>                       DOMImplementation impl = (DOMImplementation) registry
>                                       .getDOMImplementation("psvi 1.0");
>                       document = impl.createDocument(namespace, "root", null);
>               } catch (ClassCastException e) {
>                       e.printStackTrace();
>               } catch (ClassNotFoundException e) {
>                       e.printStackTrace();
>               } catch (InstantiationException e) {
>                       e.printStackTrace();
>               } catch (IllegalAccessException e) {
>                       e.printStackTrace();
>               }
>       }
> }
> Loaded schema ,file schema.xsd :
> <?xml version="1.0" encoding="UTF-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
> elementFormDefault="qualified" xmlns="http://www.example.org/schema/";
>       targetNamespace="http://www.example.org/schema/";>
>       <xs:element name="root">
>               <xs:complexType>
>                       <xs:sequence>
>                               <xs:element name="item">
>                                       <xs:complexType>
>                                               <xs:sequence>
>                                                       <xs:element name="foo" 
> type="xs:string"></xs:element>
>                                                       <xs:element name="bar" 
> type="xs:string"></xs:element>
>                                               </xs:sequence>
>                                       </xs:complexType>
>                               </xs:element>
>                       </xs:sequence>
>               </xs:complexType>
>       </xs:element>
> </xs:schema>
> Compile and run commands:
> javac -cp .;./xercesImpl.jar ValidationTest.java
> java -cp .;./xercesImpl.jar ValidationTest
> Result:
> ValidationTest start
> declaration==null //1
> declaration==null //3
> declaration==null //4
> When the element is other than document element there is no information about 
> this element declaration. Using document or documentElement to construct 
> DOMSource and DOMResult makes it works fine.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to