Using output w3c_ schema validation

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

Using output w3c_ schema validation

by Jack Rugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tatu:

I have an interesting problem for which I expect there may not be a
solution.  But, you have been giving me such good advice, I thought I
would ask.

I am creating an "XMLValidationSchemaFactory" for a
"XMLValidationSchema.SCHEMA_ID_W3C_SCHEMA", using the  "createSchema"
method to load the schema, and using the "validateAgainst" method to
trigger validation on my output.  So far so good.  The output is
validated as it is created just as it should be.

But, I need to include the
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' and
'xsi:noNamespaceSchemaLocation="myfavorite.xsd"' attributes in the root
elemnent of my output file for later use.

I can feed the "xmlns. . . " namespace information in with a
"writeNamespace" call.  But, I cannot figure out how to get the "xsi. .
. " information into my output.  If I try to use "writeAttribute", I get
an exception:

Exception in thread "main" com.ctc.wstx.exc.WstxValidationException:
unexpected
attribute "xsi:noNamespaceSchemaLocation" at [row,col {unknown-source}]:
[1,112] at
com.ctc.wstx.exc.WstxValidationException.create(WstxValidationException.
java:49)

And, as near as I can tell, you really can't define that as an attribute
in the schema, itself.

For now, I have just stopped validating the output as it is created and
am outputting the "xsi. . . " sequence with "writeAttribute".  And, it
won't be the end of the world if I have to deploy the application
without internal validation.

Jack......
-----------------------------
Jack S. Rugh
Retrieval Systems Corporation
2071 Chain Bridge Road
Suite 510
Vienna, VA 22182
703-749-0012 ext. 335
http://retrievalsystems.com
-----------------------------

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Using output w3c_ schema validation

by Cowtowncoder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 22, 2009 at 10:54 AM, Jack Rugh <jrugh@...> wrote:
> Hi Tatu:
>
> I have an interesting problem for which I expect there may not be a
> solution.  But, you have been giving me such good advice, I thought I
> would ask.

:-)

Thanks! And you are welcome, this is an excellent question again.

...
> But, I need to include the
> 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' and
> 'xsi:noNamespaceSchemaLocation="myfavorite.xsd"' attributes in the root
> elemnent of my output file for later use.
>
> I can feed the "xmlns. . . " namespace information in with a
> "writeNamespace" call.  But, I cannot figure out how to get the "xsi. .
> . " information into my output.  If I try to use "writeAttribute", I get
> an exception:

Hmmh. I need to investigate this -- it definitely should work, without
having to go through the hoops. It's just question of who  & where
should take care to ignore attributes schema spec itself uses.

But first quick question: what method are you using to write the
schema location? It has to be one that takes namespace (and prefix, if
in non-repairing mode) separately; I assume that's what you are using.

I'll file an issue for this and I hope we can tackle it for 4.1; I am
finally about to have time to work a bit on Woodstox again. And there
are a few issues related to schema validation to resolve. I take it as
a sign that functionality is finally being used, which is good. :-)

-+ Tatu +-

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



RE: Using output w3c_ schema validation

by Jack Rugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Tatu:

I had no specified a mode.  But after receiving your message, I tried
both

       
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
                 Boolean.FALSE);
and
       
outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
                 Boolean.TRUE);

and go the same result.  I also tried removing the "xsi:" prefix from
the attribute name, with both REPAIRING_NAMESPACES settings, but that
did not change the result.

Jack.....


> -----Original Message-----
> From: Tatu Saloranta [mailto:tsaloranta@...]
> Sent: Wednesday, April 22, 2009 2:48 PM
> To: user@...
> Subject: Re: [woodstox-user] Using output w3c_ schema validation
>
> On Wed, Apr 22, 2009 at 10:54 AM, Jack Rugh
> <jrugh@...> wrote:
> > Hi Tatu:
> >
> > I have an interesting problem for which I expect there may not be a
> > solution.  But, you have been giving me such good advice, I
> thought I
> > would ask.
>
> :-)
>
> Thanks! And you are welcome, this is an excellent question again.
>
> ...
> > But, I need to include the
> > 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' and
> > 'xsi:noNamespaceSchemaLocation="myfavorite.xsd"' attributes in the
> > root elemnent of my output file for later use.
> >
> > I can feed the "xmlns. . . " namespace information in with a
> > "writeNamespace" call.  But, I cannot figure out how to get
> the "xsi. .
> > . " information into my output.  If I try to use
> "writeAttribute", I
> > get an exception:
>
> Hmmh. I need to investigate this -- it definitely should
> work, without having to go through the hoops. It's just
> question of who  & where should take care to ignore
> attributes schema spec itself uses.
>
> But first quick question: what method are you using to write
> the schema location? It has to be one that takes namespace
> (and prefix, if in non-repairing mode) separately; I assume
> that's what you are using.
>
> I'll file an issue for this and I hope we can tackle it for
> 4.1; I am finally about to have time to work a bit on
> Woodstox again. And there are a few issues related to schema
> validation to resolve. I take it as a sign that functionality
> is finally being used, which is good. :-)
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Using output w3c_ schema validation

by Cowtowncoder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 22, 2009 at 1:23 PM, Jack Rugh <jrugh@...> wrote:
> Hi Tatu:
>
> I had no specified a mode.  But after receiving your message, I tried
> both

Ok. Default is non-repairing.

outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
>                 Boolean.FALSE);
> and
> outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
>                 Boolean.TRUE);
>
> and go the same result.  I also tried removing the "xsi:" prefix from
> the attribute name, with both REPAIRING_NAMESPACES settings, but that
> did not change the result.

Just to make sure: unless writer is configured to be in
"non-namespace-aware" mode (which does not work with schema
validation, since schemas are ns-aware) -- which writers are not in by
default -- local name given should never include prefix.

So call should either be:

sw.writeAttribute(URI-for-xsi,
  "noNamespaceSchemaLocation",
  "http://www.w3.org/2001/XMLSchema-instance")

(in repairing mode, which will declare that prefix automatically)

or

sw.writeAttribute("xsi", URI-for-xsi,
  "noNamespaceSchemaLocation",
  "http://www.w3.org/2001/XMLSchema-instance");

in either mode.

But important point is that 'URI-for-xsi' MUST be the exact namespace
URI that Schema specification uses... which is... lessee:

"http://www.w3.org/2001/XMLSchema-instance"

Perhaps this is the exact problem we have here? So basically local
name and namespace URI must match; prefix does not matter (unlike with
DTDs).

-+ Tatu +-

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



RE: Using output w3c_ schema validation

by Jack Rugh :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tatu:

To use the American baseball slang, you are batting 1000.  The problem
was with my understanding.  There is nothing wrong with Woodstox.  When
I changed the statement to:

extractWriter.writeAttribute("http://www.w3.org/2001/XMLSchema-instance"
,  "noNamespaceSchemaLocation",
"ExtractedDocsData.xsd");

with IS_REPARING_NAMESPACES, all was well.  I'm now gettig validation
and am outputting my root element as:

<ExtractedDocsData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ExtractedDocsData.xsd">

which is exactly what I wanted.

Many thanks,
Jack......

> -----Original Message-----
> From: Tatu Saloranta [mailto:tsaloranta@...]
> Sent: Wednesday, April 22, 2009 5:08 PM
> To: user@...
> Subject: Re: [woodstox-user] Using output w3c_ schema validation
>
> On Wed, Apr 22, 2009 at 1:23 PM, Jack Rugh
> <jrugh@...> wrote:
> > Hi Tatu:
> >
> > I had no specified a mode.  But after receiving your
> message, I tried
> > both
>
> Ok. Default is non-repairing.
>
> outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
> >                 Boolean.FALSE);
> > and
> > outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
> >                 Boolean.TRUE);
> >
> > and go the same result.  I also tried removing the "xsi:"
> prefix from
> > the attribute name, with both REPAIRING_NAMESPACES
> settings, but that
> > did not change the result.
>
> Just to make sure: unless writer is configured to be in
> "non-namespace-aware" mode (which does not work with schema
> validation, since schemas are ns-aware) -- which writers are
> not in by default -- local name given should never include prefix.
>
> So call should either be:
>
> sw.writeAttribute(URI-for-xsi,
>   "noNamespaceSchemaLocation",
>   "http://www.w3.org/2001/XMLSchema-instance")
>
> (in repairing mode, which will declare that prefix automatically)
>
> or
>
> sw.writeAttribute("xsi", URI-for-xsi,
>   "noNamespaceSchemaLocation",
>   "http://www.w3.org/2001/XMLSchema-instance");
>
> in either mode.
>
> But important point is that 'URI-for-xsi' MUST be the exact
> namespace URI that Schema specification uses... which is... lessee:
>
> "http://www.w3.org/2001/XMLSchema-instance"
>
> Perhaps this is the exact problem we have here? So basically
> local name and namespace URI must match; prefix does not
> matter (unlike with DTDs).
>
> -+ Tatu +-
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Using output w3c_ schema validation

by Cowtowncoder :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Wed, Apr 22, 2009 at 2:30 PM, Jack Rugh <jrugh@...> wrote:

> Tatu:
>
> To use the American baseball slang, you are batting 1000.  The problem
> was with my understanding.  There is nothing wrong with Woodstox.  When
> I changed the statement to:
> extractWriter.writeAttribute("http://www.w3.org/2001/XMLSchema-instance"
> ,  "noNamespaceSchemaLocation",
> "ExtractedDocsData.xsd");
>
> with IS_REPARING_NAMESPACES, all was well.  I'm now gettig validation
> and am outputting my root element as:
>
> <ExtractedDocsData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="ExtractedDocsData.xsd">
>
> which is exactly what I wanted.
>
> Many thanks,

Perfect! Glad it worked out, I am quite fond of the ability to
validate on output, not just when parsing... would be shame if it had
problem with such a common use case. :-)

-+ Tatu +-

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email