Well, it is because the tag names in your XML document have to match
<element> declarations in your Schema. Then, each element has a type,
which is used to validate that element's content. The names of the types
themselves don't correspond to tags in the instance document.

You can read the first chapters of the XML Schema primer
(http://www.w3.org/TR/xmlschema-0/), for a good introduction to
XMLSchema.

Radu

-----Original Message-----
From: Fabio Petrillo [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 03, 2006 8:04 AM
To: user@xmlbeans.apache.org
Subject: Validation problem

Hello all...i'm new about XMLBeans and i'm going to use it to validate
some XML...
here are my sample files:

FILE.XML TO BE VALIDATE:

<x:InformazioniOperatoreResponse
xmlns:x="http://regionecampania.spicca.nag/cancellazione_prenotazione.xs
d">
  <idCUP>string</idCUP>
  <DataOra>2008-09-29</DataOra>
</x:InformazioniOperatoreResponse>

extract from MYXSD.XSD:

<complexType name="InformazioniOperatoreResponse">
 <all>
  <element name="idCUP" type="string"/>
  <element name="DataOra" type="date"/>
 </all>
</complexType>


class VALIDATOR.java:
package test;

import java.io.PrintStream;
import java.util.*;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.tool.CommandLine;
import javax.xml.namespace.*;
import org.apache.xmlbeans.impl.xsd2inst.SampleXmlUtil;

public class Validator {

    public Validator()
    {
    }

    public static void printUsage()
    {
        System.out.println("Validates the specified instance against the
specified schema.");
        System.out.println("Contrast with the svalidate tool, which
validates using a stream.");
        System.out.println("Usage: validate [-dl] [-nopvr] [-noupa]
[-license] schema.xsd instance.xml");
        System.out.println("Options:");
        System.out.println("    -dl - permit network downloads for
imports and
includes (default is off)");
        System.out.println("    -noupa - do not enforce the unique
particle
attribution rule");
        System.out.println("    -nopvr - do not enforce the particle
valid
(restriction) rule");
        System.out.println("    -partial - allow partial schema type
system");
        System.out.println("    -license - prints license information");
    }

    public static void main(String args[])
    {
        Set flags = new HashSet();
        flags.add("h");
        flags.add("help");
        flags.add("usage");
        flags.add("license");
        flags.add("version");
        flags.add("dl");
        flags.add("noupa");
        flags.add("nopvr");
        flags.add("partial");
        CommandLine cl = new CommandLine(args, flags,
Collections.EMPTY_SET);
        if(cl.getOpt("h") != null || cl.getOpt("help") != null ||
cl.getOpt("usage") != null || args.length < 1)
        {
            printUsage();
            System.exit(0);
            return;
        }
        String badopts[] = cl.getBadOpts();
        if(badopts.length > 0)
        {
            for(int i = 0; i < badopts.length; i++)
                System.out.println("Unrecognized option: " +
badopts[i]);

            printUsage();
            System.exit(0);
            return;
        }
        if(cl.getOpt("license") != null)
        {
            CommandLine.printLicense();
            System.exit(0);
            return;
        }
        if(cl.getOpt("version") != null)
        {
            CommandLine.printVersion();
            System.exit(0);
            return;
        }
        if(cl.args().length == 0)
            return;

        boolean dl = cl.getOpt("dl") != null;
        boolean nopvr = cl.getOpt("nopvr") != null;
        boolean noupa = cl.getOpt("noupa") != null;
        boolean partial = cl.getOpt("partial") != null;
        java.io.File schemaFiles[] = cl.filesEndingWith(".xsd");
        java.io.File instanceFiles[] = cl.filesEndingWith(".xml");
        java.io.File jarFiles[] = cl.filesEndingWith(".jar");
        List sdocs = new ArrayList();
        for(int i = 0; i < schemaFiles.length; i++)
            try
            {
               
sdocs.add(org.apache.xmlbeans.XmlObject.Factory.parse(schemaFiles[i],
(new XmlOptions()).setLoadLineNumbers().setLoadMessageDigest()));
            }
            catch(Exception e)
            {
                System.err.println(schemaFiles[i] + " not loadable: " +
e);
            }

        XmlObject schemas[] = (XmlObject[])sdocs.toArray(new
XmlObject[0]);
        SchemaTypeLoader sLoader = null;
        Collection compErrors = new ArrayList();
        XmlOptions schemaOptions = new XmlOptions();
        schemaOptions.setErrorListener(compErrors);

        if(dl)
            schemaOptions.setCompileDownloadUrls();
        if(nopvr)
            schemaOptions.setCompileNoPvrRule();
        if(noupa)
            schemaOptions.setCompileNoUpaRule();
        if(partial)
            schemaOptions.put("COMPILE_PARTIAL_TYPESYSTEM");
        if(jarFiles != null && jarFiles.length > 0)
            sLoader =
XmlBeans.typeLoaderForResource(XmlBeans.resourceLoaderForPath(jarFiles))
;
        try
        {
            if(schemas != null && schemas.length > 0){
              sLoader = XmlBeans.compileXsd(schemas, sLoader,
schemaOptions);
            }
        }
        catch(Exception e)
        {
            if(compErrors.isEmpty() || !(e instanceof XmlException))
                e.printStackTrace(System.err);
            System.out.println("Schema invalid:" + (partial ? " couldn't
recover from errors" : ""));
            for(Iterator i = compErrors.iterator(); i.hasNext();
System.out.println(i.next()));
            return;
        }

        if(partial && !compErrors.isEmpty())
        {
            System.out.println("Schema invalid: partial schema type
system recovered");
            for(Iterator i = compErrors.iterator(); i.hasNext();
System.out.println(i.next()));
        }
        if(sLoader == null)
            sLoader = XmlBeans.getBuiltinTypeSystem();//
.getContextTypeLoader();


        for(int i = 0; i < instanceFiles.length; i++)
        {
            XmlObject xobj ;
            try
            {
                xobj = sLoader.parse(instanceFiles[i], null, (new
XmlOptions()).setLoadLineNumbers("LOAD_LINE_NUMBERS_END_ELEMENT"));
                System.out.println("Validation: " + xobj.validate());
            }
            catch(Exception e)
            {
                System.err.println(instanceFiles[i] + " not loadable: "
+ e);
                e.printStackTrace(System.err);
                continue;
            }
            Collection errors = new ArrayList();
            if(xobj.schemaType() == XmlObject.type)
            {
                System.out.println(instanceFiles[i] + " NOT valid.  ");
                System.out.println("  Document type not found.");
                continue;
            }
            System.out.println(xobj.validate());
            if(xobj.validate((new
XmlOptions()).setErrorListener(errors)))
            {
                System.out.println(instanceFiles[i] + " valid.");
                continue;
            }
            System.out.println(instanceFiles[i] + " NOT valid.");
            for(Iterator it = errors.iterator(); it.hasNext();
System.out.println(it.next()));
        }

    }
}

i'm going crazy because i can't validate correctly my XML simple file...
i notice that if my XSD structure is like the one above, the
xobj.validate() returns FALSE...
otherwise if XSD structure is like this:
<element name="InformazioniOperatoreResponse">
  <complexType >
   <all>
    <element name="idCUP" type="string"/>
    <element name="DataOra" type="date"/>
   </all>
  </complexType>
</element>
it works fine...why?
the problem is that i need to validate with the first structure of my
XSD file...as above, i'm new to XMLBeans and i think that this is a
setting of the XMLOptions passed to the parse function...
anyone can helps me ???

thanks in advance to everyone...
bye all,

Fabio Petrillo

----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to