You are viewing a plain text version of this content. The canonical link for it is here.
Posted to p-dev@xerces.apache.org by Raju Sunny <rs...@ipunity.com> on 2005/09/22 15:09:38 UTC

validate an XML against an XSD

Hi all
First question in this list from me

I am very new to XML. What i need to do is validate an XML against an 
XSD. how do i do it with XML xerces?

Thanx in advance for all help
Regards
Raju


-- 
The light at the end of the tunnel has been turned off due to budget cuts.




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


Re: validate an XML against an XSD

Posted by Stephen Collyer <sc...@netspinner.co.uk>.
Raju Sunny wrote:
> i have the XML file like this
> <?xml version="1.0" encoding="UTF-8"?>
> <IPU-Answers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> xsi:noNamespaceSchemaLocation="ipu_answers_ses.xsd" >
>         <IPU-Masterinfo>

First point: you're using a noNamespaceSchemaLocation, whereas my
example showed a schemaLocation attribute. I'd have to run your
code to see what happens here.

> now the code is something liek this
> 
> my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
> 
> #$parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreNameSpaces", 0);
> 
> #$parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreValidation", 0);
> 
> #$parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchema", 0);
> 
> #$parser->setErrorHandler(MyErrorHandler->new);

You seem to have commented all of the interesting lines out.

> my $xml = "ipu_answers.xml";
> open (HNDLR,$xml);
> my (@lines) = <HNDLR>;
>         close HNDLR;
> my $something = join (" ",@lines);
> 
> 
> eval ($parser->parse(XML::Xerces::MemBufInputSource->new($something)));
> 
> it just runs without any err and nithing happens

How do you know ? You don't seem to have set an error handler,
or enabled the correct features, due to the comments above, and you
don't seem to be checking $@.

I may be misunderstanding what you're doing in the code, as what
you've shown above looks rather odd.

> the things coloured in red means that the script exists there...

Two points

1. Please don't send HTML based messages, as not all readers
support HTML

2. I don't know what you mean by "the script exists there".
It seems to me that the script doesn't exist there, as you've
commented it out.

-- 
Regards

Stephen Collyer
Netspinner Ltd

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


Re: validate an XML against an XSD

Posted by Stephen Collyer <sc...@netspinner.co.uk>.
Raju Sunny wrote:
> Hei sorry for the completely foolish question..

Isn't this the same question ?

> i need to validate an XML file against an xsd in perl
> IS there any way for doing that using xerces c

Create a parser like this:

>     my $parser = XML::Xerces::XMLReaderFactory::createXMLReader();
> 
>     $parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreNameSpaces", 1);
> 
>     $parser->setFeature("$XML::Xerces::XMLUni::fgSAX2CoreValidation", 1);
>     $parser->setFeature("$XML::Xerces::XMLUni::fgXercesSchema", 1);

This creates a parser with the features required for schema validation.

Then feed this parser XML which specifies a schemaLocation in the
root element like e.g.

> <myelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 > xsi:schemaLocation="http://my.schema.loc/schema file:/schemas/s1.xsd">

You'll have to be prepared to catch and handle validation exceptions
in the code:

>     eval
>     {
>         $parser->parse(XML::Xerces::MemBufInputSource->new($args{xml}));
>     };
>     if ($@)
>     {

AFAIK, Xerces-C does not allow you to override the schema specified
by the XML document via the fgXercesSchemaExternalSchemaLocation
feature i.e. you can't create a parser and tell it always to
validate against a specific schema; you have to live with what's
specified in the document.

-- 
Regards

Stephen Collyer
Netspinner Ltd

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


Re: validate an XML against an XSD

Posted by Raju Sunny <rs...@ipunity.com>.
Hei sorry for the completely foolish question..
i need to validate an XML file against an xsd in perl
IS there any way for doing that using xerces c
regards
raju

The light at the end of the tunnel has been turned off due to budget cuts.



Raju Sunny wrote:

> *This message was transferred with a trial version of CommuniGate(tm) 
> Pro*
> Hi all
> First question in this list from me
>
> I am very new to XML. What i need to do is validate an XML against an 
> XSD. how do i do it with XML xerces?
>
> Thanx in advance for all help
> Regards
> Raju
>
>

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


Re: validate an XML against an XSD

Posted by Raju Sunny <rs...@ipunity.com>.
Hei sorry for the completely foolish question..
i need to validate an XML file against an xsd in perl
IS there any way for doing that using xerces c
regards
raju

The light at the end of the tunnel has been turned off due to budget cuts.

Raju Sunny
IP Unity Communications
Bangalore

+91-80-5120-8693 (Direct)
+91-80-5120-8591 x-131
+91-98864-94049 (Cell)



Raju Sunny wrote:

> *This message was transferred with a trial version of CommuniGate(tm) 
> Pro*
> Hi all
> First question in this list from me
>
> I am very new to XML. What i need to do is validate an XML against an 
> XSD. how do i do it with XML xerces?
>
> Thanx in advance for all help
> Regards
> Raju
>
>


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