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 Robert Houben <Ro...@fusionware.net> on 2004/05/03 18:10:20 UTC

Validating XML: I'm missing something...

I'm having trouble validating my XML with an external XSD when I add a
namespace.  I've looked at all the related posts on the archives and
cannot see what I'm doing wrong.  Probably too many trees in my forest!
;)

 

I get this error:

cvc-elt.1: Cannot find the declaration of element 'outer'.

 

Here is the XSD:

<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema" 

            targetNamespace="http://rhtest"

            elementFormDefault="qualified" >

   

   <s:element name="outer">

            <s:complexType>

             <s:sequence>

              <s:element name="middle">

               <s:complexType>

                <s:sequence>

                 <s:element name="inner" />

                </s:sequence>

               </s:complexType>

              </s:element>

             </s:sequence>

            </s:complexType>

   </s:element>

</s:schema>

 

Here is the instance (note the commented variation didn't work, either):

            <!--

            <x:outer xmlns:x="http://rhtest">

                        <x:middle>

                                    <x:inner/>

                        </x:middle>

            </x:outer>

            -->

            <outer xmlns="http://rhtest">

                        <middle>

                                    <inner/>

                        </middle>

            </outer>

 

And here is my code:

 

            public void loadXML(String xmlString, String
externalSchemaLocation, String namespace) throws FWTransactionException

            {

                        DOMParser parser = new DOMParser();

                        try

                        {

 
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLangua
ge",

 
"http://www.w3.org/2001/XMLSchema");

                                    parser.setFeature(

 
"http://apache.org/xml/features/validation/schema", true);

                                    parser.setFeature(

 
"http://apache.org/xml/features/validation/schema-full-checking", true);

 
parser.setFeature("http://xml.org/sax/features/namespaces",true);

 
parser.setFeature("http://xml.org/sax/features/validation",true);

                                    parser.setErrorHandler(this);

                                    if (null == namespace ||
namespace.length() == 0)

                                    {

                                                parser.setProperty(

 
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocat
ion",

 
externalSchemaLocation.replace('\\', '/'));

                                    }

                                    else

                                    {

                                                parser.setProperty(

 
"http://apache.org/xml/properties/schema/external-schemaLocation",

 
externalSchemaLocation.replace('\\', '/'));

                                    }

                                    parser.parse(new InputSource(new
ByteArrayInputStream(xmlString.getBytes())));

                        }

                        catch (SAXNotRecognizedException snre)

                        {

                                    //

                        }

                        catch (SAXNotSupportedException snre)

                        {

                                    //

                        }

                        catch (SAXException se)

                        {

                                    //

                        }

                        catch (IOException ioe)

                        {

                                    //

                        }

            }

 

TIA,