XML XSD Validation

View: New views
3 Messages — Rating Filter:   Alert me  

XML XSD Validation

by Rajeevr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am using Xerces for validating a XML against a XSD. Xsd validation can be done by two ways: noNamespaceSchemaLocation/schemaLocation.
1
I successfully validated it against XSD by using noNamespaceSchemaLocation like this:

<?xml version="1.0"?>
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="c:/dictionary.xsd">

2
But I am facing problem in schemaLocation. When I provide schemaLocation which is well accessible and available in my local machine, Xerces throws this error: cvc-elt.1: Cannot find the declaration of element 'dictionary'. I put dictionary.xsd file under tomcat and started the tomcat server. But

<?xml version="1.0"?>
<dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                        xsi:schemaLocation="http://localhost:8080/a1/ http://localhost:8080/a1/dictionary.xsd">


XSD File;
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="dictionary" type="dictionaryType"/>
        <xsd:complexType name="dictionaryType">
                <xsd:sequence>
                        <xsd:element name="word" type="wordType" maxOccurs="unbounded"/>
                </xsd:sequence>
        </xsd:complexType>
……………
……………

Someone please help me out to understand the exact problem.

Regards,
Rajeev

Re: XML XSD Validation

by G. Ken Holman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 2009-05-28 08:33 -0700, Rajeevr wrote:

>I am using Xerces for validating a XML against a XSD. Xsd validation can be
>done by two ways: noNamespaceSchemaLocation/schemaLocation.
>1
>I successfully validated it against XSD by using noNamespaceSchemaLocation
>like this:
>
><?xml version="1.0"?>
><dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>           xsi:noNamespaceSchemaLocation="c:/dictionary.xsd">
>
>2
>But I am facing problem in schemaLocation. When I provide schemaLocation
>which is well accessible and available in my local machine, Xerces throws
>this error: cvc-elt.1: Cannot find the declaration of element 'dictionary'.
>I put dictionary.xsd file under tomcat and started the tomcat server. But
>
><?xml version="1.0"?>
><dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>                         xsi:schemaLocation="http://localhost:8080/a1/
>http://localhost:8080/a1/dictionary.xsd">
>
>
>XSD File;
><?xml version="1.0"?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>         <xsd:element name="dictionary" type="dictionaryType"/>
>         <xsd:complexType name="dictionaryType">
>                 <xsd:sequence>
>                         <xsd:element
> name="word" type="wordType" maxOccurs="unbounded"/>
>                 </xsd:sequence>
>         </xsd:complexType>
>……………
>¦â€¦â€¦
>……………
>¦â€¦â€¦
>
>Someone please help me out to understand the exact problem.

As I see it your XML vocabulary doesn't use a
namespace, thus xsi:noNamespaceSchemaLocation is
working just fine as expected.  You can't expect
the xsi:schemaLocation to work when you aren't
using a namespace, because the namespace you are
naming in the attribute isn't a namespace that is being used.

The xsi:schemaLocation has an arbitrary number of
pairs of values, each pair being a namespace URI and a location URL:

    http://www.w3.org/TR/2004/REC-xmlschema-1-20041028/#schema-loc

Using this attribute is of no help if you aren't
using a namespace for your XML vocabulary.

I hope this helps.

. . . . . . . . . . Ken


--
XQuery/XSLT/XSL-FO hands-on training - Los Angeles, USA 2009-06-08
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/x/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@...
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/x/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal



RE: XML XSD Validation

by Michael Kay :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Your dictionary element is in no namespace, so you should use
noNamespaceSchemaLocation.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

> -----Original Message-----
> From: xmlschema-dev-request@...
> [mailto:xmlschema-dev-request@...] On Behalf Of Rajeevr
> Sent: 28 May 2009 16:33
> To: xmlschema-dev@...
> Subject: XML XSD Validation
>
> Hi,
>
> I am using Xerces for validating a XML against a XSD. Xsd
> validation can be done by two ways:
> noNamespaceSchemaLocation/schemaLocation.
> 1
> I successfully validated it against XSD by using
> noNamespaceSchemaLocation like this:
>
> <?xml version="1.0"?>
> <dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:noNamespaceSchemaLocation="c:/dictionary.xsd">
>
> 2
> But I am facing problem in schemaLocation. When I provide
> schemaLocation which is well accessible and available in my
> local machine, Xerces throws this error: cvc-elt.1: Cannot
> find the declaration of element 'dictionary'.
> I put dictionary.xsd file under tomcat and started the tomcat
> server. But
>
> <?xml version="1.0"?>
> <dictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://localhost:8080/a1/
> http://localhost:8080/a1/dictionary.xsd">
>
>
> XSD File;
> <?xml version="1.0"?>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <xsd:element name="dictionary" type="dictionaryType"/>
> <xsd:complexType name="dictionaryType">
> <xsd:sequence>
> <xsd:element name="word"
> type="wordType" maxOccurs="unbounded"/>
> </xsd:sequence>
> </xsd:complexType>
> .....
> .....
>
> Someone please help me out to understand the exact problem.
>
> Regards,
> Rajeev
>
> --
> View this message in context:
> http://www.nabble.com/XML-XSD-Validation-tp23764252p23764252.html
> Sent from the w3.org - xmlschema-dev mailing list archive at
> Nabble.com.
>
>
>