You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by ju...@motiondata.at on 2008/03/03 10:28:31 UTC

Antwort: Re: Antwort: Re: external-shemaLocation ... cvc-elt.1: Cannot find the declaration of element

>> Both the local name ("inquiry_A2") and namespace name
>> ("http://www.reifen.net") of the element need to match a declaration in 
the
>> schema. Since you dropped the target namespace from the schema document 
it
>> would be invalid.

since I dropped the target namespace from the schema document it still 
works. But if there is a posibility to get it working with changing only 
the coding in saveRequest and not changing xml, it will be better?

===========================
Code:
===========================
public boolean saveRequest(String userID, InputStream request) {
                Boolean ok = false;
                SAXBuilder builder = new SAXBuilder();
                builder.setEntityResolver(new NoOpEntityResolver());
                try {
                        Calendar calendar = Calendar.getInstance();
                        java.text.DateFormat df = new 
java.text.SimpleDateFormat("yyyyMMddHHmmss");
                        String timestamp = df.format(calendar.getTime());
                        String filename = this.xmlrequestpath + "/" + 
userID + "_REQUEST_" + timestamp + ".xml";
                        this.requestDoc = builder.build(request);
                        this.writeToFile(this.requestDoc, filename);
                    SAXBuilder builderValidator = new 
SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
                        builderValidator.setFeature(
                    "http://apache.org/xml/features/validation/schema", 
true);
                        builderValidator.setProperty(
 
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                    "http://localhost:8080/EDIWheel/requests/" + 
this.requestDoc.getRootElement().getName() + ".xsd");
                        builderValidator.setValidation(true);
                        this.requestDoc = 
builderValidator.build("http://localhost:8080/EDIWheel/requests/" + userID 
+ "_REQUEST_" + timestamp + ".xml");
                        ok = true;
                        // Fehler werden abgefangen und ausgegeben.
                } catch (IOException e) {
                        System.out.println("I/O Error: " + e.toString());
                } catch (JDOMException e) {
                        System.out.println("Corrupted file, because of: " 
+ e.getMessage());
                }
                return ok;
        }

===========================
Head of shema:
===========================
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:ew="http://www.reifen.net"
    xmlns:px="http://www.reifen.net/Core"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:import namespace="http://www.reifen.net/Core" 
schemaLocation="inquiry_A2_reifen.net_Core.xsd"/>

Re: Antwort: Re: Antwort: Re: external-shemaLocation ... cvc-elt.1: Cannot find the declaration of element

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Well you have to change the document but that doesn't necessarily mean you
need to modify the file on disk. You could possibly transform it in memory,
for example with a SAX filter placed before the schema validator. It's
doable using JAXP 1.3 though I can't say whether you can accomplish that
through the JDOM APIs (I'm not a user). You may want to ask in the JDOM
forum.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

juergen.kargl@motiondata.at wrote on 03/03/2008 04:28:31 AM:

>
> >> Both the local name ("inquiry_A2") and namespace name
> >> ("http://www.reifen.net") of the element need to match a declaration
in the
> >> schema. Since you dropped the target namespace from the schema
document it
> >> would be invalid.
>
> since I dropped the target namespace from the schema document it
> still works. But if there is a posibility to get it working with
> changing only the coding in saveRequest and not changing xml, it
> will be better?
>
> ===========================
> Code:
> ===========================
> public boolean saveRequest(String userID, InputStream request) {
>                 Boolean ok = false;
>                 SAXBuilder builder = new SAXBuilder();
>                 builder.setEntityResolver(new NoOpEntityResolver());
>                 try {
>                         Calendar calendar = Calendar.getInstance();
>                         java.text.DateFormat df = new java.text.
> SimpleDateFormat("yyyyMMddHHmmss");
>                         String timestamp = df.format(calendar.getTime());

>                         String filename = this.xmlrequestpath + "/"
> + userID + "_REQUEST_" + timestamp + ".xml";
>                         this.requestDoc = builder.build(request);
>                         this.writeToFile(this.requestDoc, filename);
>                     SAXBuilder builderValidator = new
> SAXBuilder("org.apache.xerces.parsers.SAXParser", true);
>                         builderValidator.setFeature(
>                     "http://apache.org/xml/features/validation/schema",
true);
>                         builderValidator.setProperty(
>                     "http://apache.
> org/xml/properties/schema/external-noNamespaceSchemaLocation",
>                     "http://localhost:8080/EDIWheel/requests/" +
> this.requestDoc.getRootElement().getName() + ".xsd");
>                         builderValidator.setValidation(true);
>                         this.requestDoc = builderValidator.build("
> http://localhost:8080/EDIWheel/requests/" + userID + "_REQUEST_" +
> timestamp + ".xml");
>                         ok = true;
>                         // Fehler werden abgefangen und ausgegeben.
>                 } catch (IOException e) {
>                         System.out.println("I/O Error: " + e.toString());

>                 } catch (JDOMException e) {
>                         System.out.println("Corrupted file, because
> of: " + e.getMessage());
>                 }
>                 return ok;
>         }
>
> ===========================
> Head of shema:
> ===========================
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema xmlns:ew="http://www.reifen.net"
>     xmlns:px="http://www.reifen.net/Core"
>     xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>   <xsd:import namespace="http://www.reifen.net/Core"
> schemaLocation="inquiry_A2_reifen.net_Core.xsd"/>


---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org