ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Martin Gainty <mgai...@hotmail.com>
Subject RE: xmlvalidate without doctype against dtd
Date Thu, 24 Feb 2011 13:49:19 GMT

at present no
you would need to identify a mechanism to load a 3rd party schema such as what axis uses in
codegen.thirdparty.schema property seen here
codegen.thirdparty.schema=xmime.xsd,soap-enc.xsd which is processed by a loadAdditionalSchema
method here

    /**
     * Loading the external schemas.
     * @return element array consisting of the the DOM element objects that represent schemas
     */
    private Element[] loadAdditionalSchemas() {
        //load additional schemas
        String[] schemaNames = ConfigPropertyFileLoader.getThirdPartySchemaNames();
        Element[] schemaElements;

        try {
            ArrayList additionalSchemaElements = new ArrayList();
            javax.xml.parsers.DocumentBuilder documentBuilder = getNamespaceAwareDocumentBuilder();
            for (int i = 0; i < schemaNames.length; i++) {
                //the location for the third party schema;s is hardcoded
                if (!"".equals(schemaNames[i].trim())) {
                    InputStream schemaStream =
                            this.getClass().getResourceAsStream(SCHEMA_PATH + schemaNames[i]);
//load in codegen.thirdparty.schema string array
                    Document doc = documentBuilder.parse(schemaStream);
                    additionalSchemaElements.add(doc.getDocumentElement());
                }
            }
            //Create the Schema element array
            schemaElements = new Element[additionalSchemaElements.size()];
            for (int i = 0; i < additionalSchemaElements.size(); i++) {
                schemaElements[i] = (Element)additionalSchemaElements.get(i);
            }
        }
       catch(SaxException s_e)
       {
          log.debug("SaxException has been thrown message="+s_e.getMessage());
        }
       catch (Exception e) {
            throw new RuntimeException(
                    CodegenMessages.getMessage("extension.additionalSchemaFailure"), e);
        }
        return schemaElements;
    }

    private DocumentBuilder getNamespaceAwareDocumentBuilder() throws ParserConfigurationException
{
        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
        documentBuilderFactory.setNamespaceAware(true);
        return documentBuilderFactory.newDocumentBuilder();
    }

the validation is done thru the javax.xml.parsers.DocumentBuilder::parse
..if parse errors occur then a SAXException is thrown as seen here in the javadoc..

parse
public abstract Document parse(InputSource is)
                        throws SAXException,
                               IOException
Parse the content of the given input source as an XML document
 and return a new DOM Document object.
 An IllegalArgumentException is thrown if the
 InputSource is null null.

Parameters:is - InputSource containing the content to be parsed.
Returns:A new DOM Document object.
Throws:
IOException - If any IO errors occur.
SAXException - If any parse errors occur.See Also:DocumentHandler

where the loadAdditionalSchemas method is implemented here:
    try {
            // load the actual utility class
            Class clazz = null;
            try {
                clazz = getClass().getClassLoader().loadClass(XMLBEANS_UTILITY_CLASS);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException("XMLBeans binding extension not in classpath");
            }

            //use reflection to invoke utility class method for actual processing
            Method method = clazz.getMethod(XMLBEANS_PROCESS_METHOD,
                                            new Class[] { List.class, Element[].class,
                                                    CodeGenConfiguration.class, String.class
});

            Element[] additionalSchemas = loadAdditionalSchemas();
            TypeMapper mapper = (TypeMapper)method.invoke(null,
                                                          new Object[] { schemas, additionalSchemas,
                                                                  configuration, typeSystemName
});
            // set the type mapper to the config
            configuration.setTypeMapper(mapper);
        } 
       catch (Exception e)
       {
            if (e instanceof RuntimeException) {
                throw (RuntimeException)e;
            } else {
                throw new RuntimeException(e);
            }
        }

i dont believe this functionality is in the base ant package
we could however write this into a new xmlvalidate_sax target and taskdef the class that contains
the parse
Martin Gainty 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni
et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten
wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist
unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet
keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen
wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire
prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe
quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information
seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les
email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune
responsabilité pour le contenu fourni.




> Subject: xmlvalidate without doctype against dtd
> Date: Thu, 24 Feb 2011 13:53:02 +0100
> From: Gabriel.Lukacs@siemens.com
> To: user@ant.apache.org
> 
> Hello,
>     is it possible to validate (via ANT xmlValidate) an xml file
> (without <!DOCTYPE ..../>) against DTD schema stored locally on
> filesystem? Pls write such an xmlValidate task.
>  
> Thanks in advance.
> Regards, Gabo.
 		 	   		  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message