You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by Kelly Beard <ke...@gmail.com> on 2010/01/07 16:55:43 UTC

Directing SAX2 where to find the XSD

I've just now started using SAX2 because I like the callback method it
provides.  Problem is my xml files are coming in a directory where the
XSD isn't so parse() is bailing because the document isn't valid.  The
parsing routine is expecting the XSD to be in the same directory as
the XML.  The schemaLocation thing doesn't work like I thought and
changing this doesn't do anything.  So what so I need to do to give
the parser some direction?  I'm setting up my parser like so:

    parser = XMLReaderFactory::createXMLReader();
    parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);   // optional
    parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);
    parser->setValidationConstraintFatal(true);
    parser->setExitOnFirstFatalError(true);

    defaultHandler = new AuthNotifyHandler();
    parser->setContentHandler(defaultHandler);
    parser->setErrorHandler(defaultHandler);

Thanks as usual!

-- 
Kelly Beard

Re: Directing SAX2 where to find the XSD

Posted by David Bertoni <db...@apache.org>.
On 1/11/2010 9:44 AM, Kelly Beard wrote:
> Having said that, I've stumbled on setExternalSchemaLocation().  Maybe
> that's what I'm looking for vs. EntityResolver?
That will work for a particular namespace, but it can be tiresome if you 
have many namespaces and schemas to support. Also, it will only support 
URLs, whereas an EntityResolver can return a custom InputSource for any 
sort of stream.

You should probably use EntityResolver, rather than XMLEntityResolver, 
unless you need the extra features the latter supports.

Dave

Re: Directing SAX2 where to find the XSD

Posted by Kelly Beard <ke...@gmail.com>.
Having said that, I've stumbled on setExternalSchemaLocation().  Maybe
that's what I'm looking for vs. EntityResolver?

On Mon, Jan 11, 2010 at 10:22 AM, Kelly Beard <ke...@gmail.com> wrote:
> I guess what I'd rather have for the second part of the schemaLocation
> is a plain xsd filename and the XML stuff use some kind of path
> mechanism to find the file, but I'll try out an XMLEntityResolver and
> see how that goes.  Thanks for the help again Dave.
>
> On Thu, Jan 7, 2010 at 1:51 PM, David Bertoni <db...@apache.org> wrote:
>> On 1/7/2010 8:21 AM, Kelly Beard wrote:
>>>
>>> Ugh.  I am so dumb.  Nevermind.  Before I had this:
>>>
>>> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
>>> <authNotify
>>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>     xmlns="http://www.quikq.com/xsd/authNotify"
>>>     xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
>>> authNotify.xsd">
>>>
>>> I changed it to this:
>>>
>>> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
>>> <authNotify
>>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>>     xmlns="http://www.quikq.com/xsd/authNotify"
>>>     xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
>>> /home/dfcuser/authNotify.xsd">
>>>
>>> Initially it didn't work this way either.  I scratched my head
>>> thinking that I knew I had XSD's in my HOME directory, what could be
>>> wrong?  Well, my home directory isn't /home/dfcuser and I had no XSDs
>>> there at all.  I copied them over and all is good now.  If you specify
>>> no path the parser defaults to the same directory as the instance
>>> document.  At least I have this email to remind me when dumbness
>>> strikes again.  :-)
>>
>> You can also use an EntityResolver to accomplish this without modifying your
>> schema documents. Search the archives for more information, or take a look
>> at the Redirect sample application.
>>
>> Dave
>>
>
>
>
> --
> Kelly Beard
>



-- 
Kelly Beard

Re: Directing SAX2 where to find the XSD

Posted by Kelly Beard <ke...@gmail.com>.
I guess what I'd rather have for the second part of the schemaLocation
is a plain xsd filename and the XML stuff use some kind of path
mechanism to find the file, but I'll try out an XMLEntityResolver and
see how that goes.  Thanks for the help again Dave.

On Thu, Jan 7, 2010 at 1:51 PM, David Bertoni <db...@apache.org> wrote:
> On 1/7/2010 8:21 AM, Kelly Beard wrote:
>>
>> Ugh.  I am so dumb.  Nevermind.  Before I had this:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
>> <authNotify
>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>     xmlns="http://www.quikq.com/xsd/authNotify"
>>     xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
>> authNotify.xsd">
>>
>> I changed it to this:
>>
>> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
>> <authNotify
>>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>     xmlns="http://www.quikq.com/xsd/authNotify"
>>     xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
>> /home/dfcuser/authNotify.xsd">
>>
>> Initially it didn't work this way either.  I scratched my head
>> thinking that I knew I had XSD's in my HOME directory, what could be
>> wrong?  Well, my home directory isn't /home/dfcuser and I had no XSDs
>> there at all.  I copied them over and all is good now.  If you specify
>> no path the parser defaults to the same directory as the instance
>> document.  At least I have this email to remind me when dumbness
>> strikes again.  :-)
>
> You can also use an EntityResolver to accomplish this without modifying your
> schema documents. Search the archives for more information, or take a look
> at the Redirect sample application.
>
> Dave
>



-- 
Kelly Beard

Re: Directing SAX2 where to find the XSD

Posted by David Bertoni <db...@apache.org>.
On 1/7/2010 8:21 AM, Kelly Beard wrote:
> Ugh.  I am so dumb.  Nevermind.  Before I had this:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <authNotify
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xmlns="http://www.quikq.com/xsd/authNotify"
>      xsi:schemaLocation="http://www.quikq.com/xsd/authNotify authNotify.xsd">
>
> I changed it to this:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
> <authNotify
>      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>      xmlns="http://www.quikq.com/xsd/authNotify"
>      xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
> /home/dfcuser/authNotify.xsd">
>
> Initially it didn't work this way either.  I scratched my head
> thinking that I knew I had XSD's in my HOME directory, what could be
> wrong?  Well, my home directory isn't /home/dfcuser and I had no XSDs
> there at all.  I copied them over and all is good now.  If you specify
> no path the parser defaults to the same directory as the instance
> document.  At least I have this email to remind me when dumbness
> strikes again.  :-)
You can also use an EntityResolver to accomplish this without modifying 
your schema documents. Search the archives for more information, or take 
a look at the Redirect sample application.

Dave

Re: Directing SAX2 where to find the XSD

Posted by Kelly Beard <ke...@gmail.com>.
Ugh.  I am so dumb.  Nevermind.  Before I had this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<authNotify
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.quikq.com/xsd/authNotify"
    xsi:schemaLocation="http://www.quikq.com/xsd/authNotify authNotify.xsd">

I changed it to this:

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<authNotify
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.quikq.com/xsd/authNotify"
    xsi:schemaLocation="http://www.quikq.com/xsd/authNotify
/home/dfcuser/authNotify.xsd">

Initially it didn't work this way either.  I scratched my head
thinking that I knew I had XSD's in my HOME directory, what could be
wrong?  Well, my home directory isn't /home/dfcuser and I had no XSDs
there at all.  I copied them over and all is good now.  If you specify
no path the parser defaults to the same directory as the instance
document.  At least I have this email to remind me when dumbness
strikes again.  :-)

On Thu, Jan 7, 2010 at 9:55 AM, Kelly Beard <ke...@gmail.com> wrote:
> I've just now started using SAX2 because I like the callback method it
> provides.  Problem is my xml files are coming in a directory where the
> XSD isn't so parse() is bailing because the document isn't valid.  The
> parsing routine is expecting the XSD to be in the same directory as
> the XML.  The schemaLocation thing doesn't work like I thought and
> changing this doesn't do anything.  So what so I need to do to give
> the parser some direction?  I'm setting up my parser like so:
>
>    parser = XMLReaderFactory::createXMLReader();
>    parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
>    parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true);   // optional
>    parser->setFeature(XMLUni::fgXercesValidationErrorAsFatal, true);
>    parser->setValidationConstraintFatal(true);
>    parser->setExitOnFirstFatalError(true);
>
>    defaultHandler = new AuthNotifyHandler();
>    parser->setContentHandler(defaultHandler);
>    parser->setErrorHandler(defaultHandler);
>
> Thanks as usual!
>
> --
> Kelly Beard
>



-- 
Kelly Beard