You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Mukul Gandhi <mu...@apache.org> on 2009/11/11 10:44:12 UTC

XML Schema prefix while using XPath expressions in assertions

Hi all,
   We specify XSD 1.1 Schema, and a sample assertions something like below:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
   ...
   <xs:assert test="xs:string(test) eq 'xxx'" />
   ...
</xs:schema>

The current implementation of XSD 1.1 assertions within Xerces-J,
while invoking the PsychoPath XPath 2.0 engine, constructs a namespace
binding in a kind of map (actually Xerces-J adds all the needed
namespace definitions for PsychoPath, in a XPath 2.0 "DynamicContext"
object), that is passed to the PsychoPath engine, while doing an XPath
2 evaluation.

One of the namespace bindings that Xerces-J initializes for PsychoPath
is the XML Schema namespace. This is done as following, with an
PsychoPath API:

DynamicContext.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");

This is an important namespace binding, that Xerces-J has to
initialize for XPath 2 evaluation with PsychoPath.

The prefix "xs" is presently hardcoded in Xerces-J, which means that
presently only this particular prefix can be functionally used while
evaluating XPath expressions, with PsychoPath. This has significance,
when we use any constructs from the XML Schema namespace, like say
xs:string in assertion XPath 2.0 expressions.

For the above XSD 1.1 example, the assertion would evaluate fine as
expected (because the prefix "xs" was used in XPath 2 expression. And
ironically, Xerces-J currently does not enforce statically the binding
between prefix "xs" in assertion XPath expressions and the Schema
namespace URI that is defined on xs:schema element. Is this an
important issue to look at?). But following assertions would fail (it
would return false), if written in the XSD 1.1 schema:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  ...
  <xsd:assert test="xsd:string(test) eq 'xxx'" />

(because the XPath expression in assertions uses the prefix "xsd" for
XML schema. But the whole XSD 1.1 schema looks correct.)

Currently, Xerces-J plus PsychoPath engine cannot utilize any other
XSD prefix (than, "xs") for assertion XPath 2 expressions. The problem
happens for following expression, in above XSD 1.1 Schema:

xsd:string(test) eq 'xxx'

While rest of Schema would execute fine.

So presently, a convention (i.e, prefix "xs" for namespace
http://www.w3.org/2001/XMLSchema) controls the XPath expressions that
are evaluated by PsychoPath engine.

Ideally, I would wish that Xerces-J can create a XML Schema namespace
binding for PsychoPath engine as following:

DynamicContext.add_namespace("xx", "http://www.w3.org/2001/XMLSchema");

Where, the XSD prefix string "xx" would be read dynamically from the
actual XSD Schema at runtime.

Should something like this must be done, to support assertions? If
yes, an advise on the design for this would be helpful.


-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   Thanks for the explanation. Now I think, I understand the concepts
in relation to this thread.

I'll update the Xerces assertions code based on the explanation you've
given below. I'll update the list, when I have completed the code
changes.

On Sun, Nov 15, 2009 at 10:32 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I stand by what I said before. The namespace bindings for the schema and F&O
> namespaces have no special standing. You may potentially need all of the
> in-scope namespace at the assert element in order to process the XPath. If
> PsychoPath is only made aware of those two namespaces how could it ever
> process an XPath like "@my:length eq fn:count(./a:children/b:grandchildren)"
> correctly (where "my", "a" and "b" are bound to other namespaces in the
> user's schema)? PsychoPath can't know what those bindings are unless it's
> explicitly told what they are.
>
> The static context does include all the in-scope namespaces. See section
> 3.13.6.2 in the spec [1]:
>
> 2.2  The static context is given as follows:
>  ...
>  2.2.2 The statically known namespaces is the {namespace bindings} of X.
>  2.2.3 The default element/type namespace is the {default namespace} of X.
>  2.2.4 The default function namespace is
> http://www.w3.org/2005/xpath-functions.
>  ...
>
> where {namespace bindings} is defined [2] as: "A set of Namespace Binding
> property records. Each member corresponds to an entry in the [in-scope
> namespaces] of the host element, with {prefix} being the [prefix] and
> {namespace} the [namespace name]."
>
> This has to be captured from the schema document and communicated to the
> XPath processor in order to have a correct implementation. The opportunity
> to retrieve the in-scope namespaces is in the traverser. For example:
>
> NamespaceSupport namespaceContext = schemaDoc.fNamespaceSupport;
> Enumeration currPrefixes = namespaceContext.getAllPrefixes();
> while (currPrefixes.hasMoreElements()) {
>     String prefix = (String)currPrefixes.nextElement();
>     String uri = namespaceContext.getURI(prefix);
>     // Store each prefix mapping on the XSAssert component.
>     ...
> }
>
> Hoping that makes sense.
>
> Thanks.
>
> [1] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-xpath-valid
> [2] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#declare-assertion
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   The changes are committed to Xerces SVN, relating to the
improvements to namespace bindings implementation, for PsychoPath
XPath 2 static context, as per the explanation you gave at the bottom
of this mail.

All my local tests for assertions and CTA pass as previously, and I am
satisfied with functional completeness, for use case we are discussing
in this thread.

You and others could please verify these fixes, and suggest further
improvements please.

On Sun, Nov 15, 2009 at 10:32 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I stand by what I said before. The namespace bindings for the schema and F&O
> namespaces have no special standing. You may potentially need all of the
> in-scope namespace at the assert element in order to process the XPath. If
> PsychoPath is only made aware of those two namespaces how could it ever
> process an XPath like "@my:length eq fn:count(./a:children/b:grandchildren)"
> correctly (where "my", "a" and "b" are bound to other namespaces in the
> user's schema)? PsychoPath can't know what those bindings are unless it's
> explicitly told what they are.
>
> The static context does include all the in-scope namespaces. See section
> 3.13.6.2 in the spec [1]:
>
> 2.2  The static context is given as follows:
>  ...
>  2.2.2 The statically known namespaces is the {namespace bindings} of X.
>  2.2.3 The default element/type namespace is the {default namespace} of X.
>  2.2.4 The default function namespace is
> http://www.w3.org/2005/xpath-functions.
>  ...
>
> where {namespace bindings} is defined [2] as: "A set of Namespace Binding
> property records. Each member corresponds to an entry in the [in-scope
> namespaces] of the host element, with {prefix} being the [prefix] and
> {namespace} the [namespace name]."
>
> This has to be captured from the schema document and communicated to the
> XPath processor in order to have a correct implementation. The opportunity
> to retrieve the in-scope namespaces is in the traverser. For example:
>
> NamespaceSupport namespaceContext = schemaDoc.fNamespaceSupport;
> Enumeration currPrefixes = namespaceContext.getAllPrefixes();
> while (currPrefixes.hasMoreElements()) {
>     String prefix = (String)currPrefixes.nextElement();
>     String uri = namespaceContext.getURI(prefix);
>     // Store each prefix mapping on the XSAssert component.
>     ...
> }
>
> Hoping that makes sense.
>
> Thanks.
>
> [1] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-xpath-valid
> [2] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#declare-assertion
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

I stand by what I said before. The namespace bindings for the schema and
F&O namespaces have no special standing. You may potentially need all of
the in-scope namespace at the assert element in order to process the XPath.
If PsychoPath is only made aware of those two namespaces how could it ever
process an XPath like "@my:length eq fn:count
(./a:children/b:grandchildren)" correctly (where "my", "a" and "b" are
bound to other namespaces in the user's schema)? PsychoPath can't know what
those bindings are unless it's explicitly told what they are.

The static context does include all the in-scope namespaces. See section
3.13.6.2 in the spec [1]:

2.2  The static context is given as follows:
 ...
 2.2.2 The statically known namespaces is the {namespace bindings} of X.
 2.2.3 The default element/type namespace is the {default namespace} of X..
 2.2.4 The default function namespace is
http://www.w3.org/2005/xpath-functions.
 ...:

where {namespace bindings} is defined [2] as: "A set of Namespace Binding
property records. Each member corresponds to an entry in the [in-scope
namespaces] of the host element, with {prefix} being the [prefix] and
{namespace} the [namespace name]."

This has to be captured from the schema document and communicated to the
XPath processor in order to have a correct implementation. The opportunity
to retrieve the in-scope namespaces is in the traverser. For example:

NamespaceSupport namespaceContext = schemaDoc.fNamespaceSupport;
Enumeration currPrefixes = namespaceContext.getAllPrefixes();
while (currPrefixes.hasMoreElements()) {
    String prefix = (String)currPrefixes.nextElement();
    String uri = namespaceContext.getURI(prefix);
    // Store each prefix mapping on the XSAssert component.);
    ...
}

Hoping that makes sense.

Thanks.

[1] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-xpath-valid
[2] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#declare-assertion

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/14/2009 09:47:35 PM:

> Hi Michael,
>    Thanks for ideas. Nice ones I believe.
>
> On Sun, Nov 15, 2009 at 12:24 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > I'm still scratching my head over how this is implemented, now with
> > specialized methods for getting and setting prefixes for the schema and
F&O
> > namespaces.
>
> :-) I'll try to explain this.
>
> > We shouldn't need to special case them.  These namespaces are
> > no more or less special than the user's namespaces and really all
should be
> > pulled from the SchemaNamespaceSupport in the traverser.  We should be
able
> > to copy all of the in-scope namespace bindings from the
> > SchemaNamespaceSupport object on to the static context in PsychoPath
and
> > that will include bindings for the schema and F&O namespaces if they
exist.
>
> You have certainly suggested a better design for this particular need.
> But I think, we can retrieve SchemaNamespaceSupport object only from
> the object, XSDocumentInfo. Or is there any other way?
>
> I presently store the XSD and XPath 2 F&O namespace prefixes in the
> object, XSAssertImpl. At first though that didn't look a nice design
> to me, because the object XSAssertImpl is specific to assertions, and
> how could we store a global string, like the XSD prefix and F&O prefix
> in this object, and there is also a bit of redundancy in this design,
> because all XSAssertImpl objects store this particular information
> (i.e, the XSD & F&O prefix).
>
> In the logic that I implemented, I get the XSD and F&O prefix only
> from the 1st XSAssertImpl object in the list. This technique achieves
> our functional requirements, to retrieve XSD and F&O prefixes, that
> need to be set on the PsychoPath dynamic context object.
>
> When I look at this design from another perspective, it also looks
> correct to me. The requirement to store the XSD and F&O prefix into
> XSAssertImpl is special to assertions, and using the object
> XSAssertImpl as a store for this, look correct to me. In fact I chose
> this design, because I couldn't find any other way to access the XSD
> and F&O prefixes (or say, the objects SchemaNamespaceSupport or
> schemaDoc), from within AbstractPsychoPathImpl.java. The objects
> SchemaNamespaceSupport or schemaDoc are available in traversers, and
> seemingly not after that flow (i.e, in the XMLSchemaValidator layer).
>
> I think, it's not right to set all namespace bindings present on the
> <schema> element to the PsychoPath static context. We only need to set
> the XSD and XPath 2 F&O bindings to PsychoPath. To my opinion, setting
> anything else to namespace bindings on PsychoPath static context, from
> the <schema> element is redundancy, and also likely functionally
> wrong.
>
> > Is that what you were ultimately planning to do, with these recent
changes
> > just being an intermediate step to eliminate the hard-coding whichwas
there
> > before?
>
> yes :)
>
> But definetely, I am going to rethink the design for this requirement
> based on your suggestion. As of now, though the logic which I
> implemented seem to achieve the funtional objectives of this use case.
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   Thanks for ideas. Nice ones I believe.

On Sun, Nov 15, 2009 at 12:24 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> I'm still scratching my head over how this is implemented, now with
> specialized methods for getting and setting prefixes for the schema and F&O
> namespaces.

:-) I'll try to explain this.

> We shouldn't need to special case them.  These namespaces are
> no more or less special than the user's namespaces and really all should be
> pulled from the SchemaNamespaceSupport in the traverser.  We should be able
> to copy all of the in-scope namespace bindings from the
> SchemaNamespaceSupport object on to the static context in PsychoPath and
> that will include bindings for the schema and F&O namespaces if they exist.

You have certainly suggested a better design for this particular need.
But I think, we can retrieve SchemaNamespaceSupport object only from
the object, XSDocumentInfo. Or is there any other way?

I presently store the XSD and XPath 2 F&O namespace prefixes in the
object, XSAssertImpl. At first though that didn't look a nice design
to me, because the object XSAssertImpl is specific to assertions, and
how could we store a global string, like the XSD prefix and F&O prefix
in this object, and there is also a bit of redundancy in this design,
because all XSAssertImpl objects store this particular information
(i.e, the XSD & F&O prefix).

In the logic that I implemented, I get the XSD and F&O prefix only
from the 1st XSAssertImpl object in the list. This technique achieves
our functional requirements, to retrieve XSD and F&O prefixes, that
need to be set on the PsychoPath dynamic context object.

When I look at this design from another perspective, it also looks
correct to me. The requirement to store the XSD and F&O prefix into
XSAssertImpl is special to assertions, and using the object
XSAssertImpl as a store for this, look correct to me. In fact I chose
this design, because I couldn't find any other way to access the XSD
and F&O prefixes (or say, the objects SchemaNamespaceSupport or
schemaDoc), from within AbstractPsychoPathImpl.java. The objects
SchemaNamespaceSupport or schemaDoc are available in traversers, and
seemingly not after that flow (i.e, in the XMLSchemaValidator layer).

I think, it's not right to set all namespace bindings present on the
<schema> element to the PsychoPath static context. We only need to set
the XSD and XPath 2 F&O bindings to PsychoPath. To my opinion, setting
anything else to namespace bindings on PsychoPath static context, from
the <schema> element is redundancy, and also likely functionally
wrong.

> Is that what you were ultimately planning to do, with these recent changes
> just being an intermediate step to eliminate the hard-coding which was there
> before?

yes :)

But definetely, I am going to rethink the design for this requirement
based on your suggestion. As of now, though the logic which I
implemented seem to achieve the funtional objectives of this use case.



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Also, it's not safe to assume that the prefix of the schema element will
have the same binding as on the assert element.

>From SVN rev 836132:
> assertImpl.setXsdNamespacePrefix(schemaDoc.fSchemaElement.getPrefix());

The prefix could be redeclared and bound to some other namespace. For
example:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
 <bar:element xmlns:xs="http://www.something.else.com"
              xmlns:bar="http://www.w3.org/2001/XMLSchema"
              name="foo">
 ...
 </bar:element>
</xs:schema>

Again, this could all be handled cleanly by pulling the in-scope namespaces
from the SchemaNamespaceSupport at the point where we're traversing the
xs:assert.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Michael Glavassevich <mr...@ca.ibm.com> wrote on 11/14/2009 01:54:21 PM:

> Hi Mukul,
>
> I'm still scratching my head over how this is implemented, now with
> specialized methods for getting and setting prefixes for the schema
> and F&O namespaces.  We shouldn't need to special case them.  These
> namespaces are no more or less special than the user's namespaces
> and really all should be pulled from the SchemaNamespaceSupport in
> the traverser.  We should be able to copy all of the in-scope
> namespace bindings from the SchemaNamespaceSupport object on to the
> static context in PsychoPath and that will include bindings for the
> schema and F&O namespaces if they exist. Is that what you were
> ultimately planning to do, with these recent changes just being an
> intermediate step to eliminate the hard-coding which was there before?
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org
>
> Mukul Gandhi <mu...@apache.org> wrote on 11/14/2009 10:57:10 AM:
>
> > Hi all,
> >    I wrote a quick blog post, trying to explain what these bug fixes
> > and enhancments achieved. ref,
> > http://mukulgandhi.blogspot.com/2009/11/xerces-j-xsd-11-update-bug-
> > fixes-and.html.
> >
> > Any comments are welcome please.
> >
> > On Sat, Nov 14, 2009 at 1:16 PM, Mukul Gandhi <mu...@apache.org>
wrote:
> > > Hi all,
> > >   The improvements for XSD namespace prefix which we are discussing
> > > in this thread, while using XSD 1.1 assertions and also CTA (when
> > > using the full XPath 2 mode) have gone into SVN.
> > >
> > > Interestingly, solving the XSD namespace prefix issue for assertions,
> > > has fixed the same problem which existed in Xerces CTA
implementation.
> > >
> > > I am satisfied with the current Xerces SVN code's functional
> > > capabilities for assertions and CTA. The new Xerces SVN code after
> > > this commit has a same functional capability as before, but with the
> > > XSD namespace prefix enhancements, which we discussed in this thread.
> > >
> > > It would be great, if anybody may like to test the newly committed
> > > code, and suggest possible improvements.
> >
> >
> >
> > --
> > Regards,
> > Mukul Gandhi
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> > For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

I'm still scratching my head over how this is implemented, now with
specialized methods for getting and setting prefixes for the schema and F&O
namespaces.  We shouldn't need to special case them.  These namespaces are
no more or less special than the user's namespaces and really all should be
pulled from the SchemaNamespaceSupport in the traverser.  We should be able
to copy all of the in-scope namespace bindings from the
SchemaNamespaceSupport object on to the static context in PsychoPath and
that will include bindings for the schema and F&O namespaces if they exist.
Is that what you were ultimately planning to do, with these recent changes
just being an intermediate step to eliminate the hard-coding which was
there before?

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/14/2009 10:57:10 AM:

> Hi all,
>    I wrote a quick blog post, trying to explain what these bug fixes
> and enhancments achieved. ref,
> http://mukulgandhi.blogspot.com/2009/11/xerces-j-xsd-11-update-bug-
> fixes-and.html.
>
> Any comments are welcome please.
>
> On Sat, Nov 14, 2009 at 1:16 PM, Mukul Gandhi <mu...@apache.org> wrote:
> > Hi all,
> >   The improvements for XSD namespace prefix which we are discussing
> > in this thread, while using XSD 1.1 assertions and also CTA (when
> > using the full XPath 2 mode) have gone into SVN.
> >
> > Interestingly, solving the XSD namespace prefix issue for assertions,
> > has fixed the same problem which existed in Xerces CTA implementation.
> >
> > I am satisfied with the current Xerces SVN code's functional
> > capabilities for assertions and CTA. The new Xerces SVN code after
> > this commit has a same functional capability as before, but with the
> > XSD namespace prefix enhancements, which we discussed in this thread.
> >
> > It would be great, if anybody may like to test the newly committed
> > code, and suggest possible improvements.
>
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi all,
   I wrote a quick blog post, trying to explain what these bug fixes
and enhancments achieved. ref,
http://mukulgandhi.blogspot.com/2009/11/xerces-j-xsd-11-update-bug-fixes-and.html.

Any comments are welcome please.

On Sat, Nov 14, 2009 at 1:16 PM, Mukul Gandhi <mu...@apache.org> wrote:
> Hi all,
>   The improvements for XSD namespace prefix which we are discussing
> in this thread, while using XSD 1.1 assertions and also CTA (when
> using the full XPath 2 mode) have gone into SVN.
>
> Interestingly, solving the XSD namespace prefix issue for assertions,
> has fixed the same problem which existed in Xerces CTA implementation.
>
> I am satisfied with the current Xerces SVN code's functional
> capabilities for assertions and CTA. The new Xerces SVN code after
> this commit has a same functional capability as before, but with the
> XSD namespace prefix enhancements, which we discussed in this thread.
>
> It would be great, if anybody may like to test the newly committed
> code, and suggest possible improvements.



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi all,
   The improvements for XSD namespace prefix which we are discussing
in this thread, while using XSD 1.1 assertions and also CTA (when
using the full XPath 2 mode) have gone into SVN.

Interestingly, solving the XSD namespace prefix issue for assertions,
has fixed the same problem which existed in Xerces CTA implementation.

I am satisfied with the current Xerces SVN code's functional
capabilities for assertions and CTA. The new Xerces SVN code after
this commit has a same functional capability as before, but with the
XSD namespace prefix enhancements, which we discussed in this thread.

It would be great, if anybody may like to test the newly committed
code, and suggest possible improvements.

Regarding the performance enahncements which Michael suggested,
relating to compiled assert XPath expression, I'll try to do that
asap. This particular performance enahcement looks doable to me. But
the amount of changes that will happen to Xerces code relating to
this, look like can be large, and may affect quite a few of Xerces
APIs. So I wish to do this change a bit cautiously, and can submit
code for review, after I am able to do enough testing.

Also I think, there is no need for a panic about performace, relating
to the current SVN code, for Xerces assertions. The users would not
likely notice any performance degradation for most commonly used XSD
1.1 schemas, that will use Xerces assertions. Also given the
computer's CPU capabilities, and memories which users currently use
for software applications, I personally see this issue not a major
risk at the moment. But definetely, we should try to improve the
Xerces implementation in this regard.

On Fri, Nov 13, 2009 at 11:41 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I had a deeper look at what's currently in SVN and it's quite different than
> what I would have expected to see, perhaps in part due to the design of
> PsychoPath. I was hoping to find a separation between the parsing /
> processing of the XPath expressions and their evaluation during schema
> validation, with the work for the XPath parsing / processing being done once
> during schema loading (or deferred until it's actually needed). This is a
> pattern supported by the JAXP XPath API, where you compile [1] an XPath
> expression and use / reuse this compiled expression for evaluation [2] many
> times. The compilation step is potentially expensive but you only pay for
> this cost once.
>
> It seems that we pay for the XPath parsing every time we evaluate an
> expression. I can't imagine that would have good performance. I'm hoping
> that there's a better way of doing this where the parsing of the XPath
> expression is done during schema loading which is also the best place to be
> pulling the namespace bindings from the schema document.
>
> What do you think?
>
> Thanks.
>
> [1]
> http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPath.html#compile(java.lang.String)
> [2]
> http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPathExpression.html#evaluate(java.lang.Object)
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael and all,
   These changes have now gone into SVN. As discussed in this thread,
the new solution optimizes assertions runtime performance by storing
the compiled XPath 2 expressions, while performing XSD traversal
actions. The compiled XPath expressions are retrieved, when the
assertions XPath are actually evaluated.

To my opinion (and originally thought about by Michael), this can
significantly improve assertions evaluation runtime performance,
particularly for large XML trees.

I am happy with the functional correctness of this SVN commit. Kindly
evaluate this code change, and suggest further improvements please.

On Mon, Nov 16, 2009 at 7:02 PM, Mukul Gandhi <mu...@apache.org> wrote:
> Hi Michael,
>   I have begun thinking, about the code changes for the design
> improvements we agreed, to make assertions (it seems, CTA psychopath
> expressions are not affected by this issue) psychopath XPath 2
> expressions to evaluate efficiently.
>
> I hope to submit first version of these improvements, by end of this
> week. I might submit the improvements earlier, if any major issues in
> this process don't appear.



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   I have begun thinking, about the code changes for the design
improvements we agreed, to make assertions (it seems, CTA psychopath
expressions are not affected by this issue) psychopath XPath 2
expressions to evaluate efficiently.

I hope to submit first version of these improvements, by end of this
week. I might submit the improvements earlier, if any major issues in
this process don't appear.

On Sun, Nov 15, 2009 at 1:00 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> This is certainly a better design (though see my other comments on this
> thread about processing the namespace bindings). Feel free to implement it
> if you're interested.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

This is certainly a better design (though see my other comments on this
thread about processing the namespace bindings). Feel free to implement it
if you're interested.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/13/2009 06:10:53 AM:

> Hi Michael,
>    This seems to be a very nice idea.
>
> Presently, the assertions XPath expressions are compiled each time an
> assertion is evaluated. As you rightly explained, this looks certainly
> expensive (and infact I feel, this can become quite expensive for
> large XML trees with repeating XML fragments, whose XSD types may
> define assertions).
>
> The optimization you have suggested seems doable and looks even
> conceptually simple to implement.
>
> I think, we can store the complied assert XPath expression, in
> XPath20Assert.java where we are presently keeping a XPath string
> representation. This new design looks to me, a quite optimized
> implementation, and would likely save a significant runtime cost.
>
> It looks to me that, it might be easier to store the XSD namespace
> prefix in the object, XSAssertImpl. We can populate this information
> while performing the assertions traversal actions on the XSD simple
> and complex types. This looks achievable to me.
>
> Can I begin doing these improvements? Any more suggestions regarding
> these issues, would be great :)
>
> On Fri, Nov 13, 2009 at 11:41 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > Hi Mukul,
> >
> > I had a deeper look at what's currently in SVN and it's quite different
than
> > what I would have expected to see, perhaps in part due to the design of
> > PsychoPath. I was hoping to find a separation between the parsing /
> > processing of the XPath expressions and their evaluation during schema
> > validation, with the work for the XPath parsing / processing beingdone
once
> > during schema loading (or deferred until it's actually needed). This is
a
> > pattern supported by the JAXP XPath API, where you compile [1] an XPath
> > expression and use / reuse this compiled expression for evaluation [2]
many
> > times. The compilation step is potentially expensive but you only pay
for
> > this cost once.
> >
> > It seems that we pay for the XPath parsing every time we evaluate an
> > expression. I can't imagine that would have good performance. I'm
hoping
> > that there's a better way of doing this where the parsing of the XPath
> > expression is done during schema loading which is also the best place
to be
> > pulling the namespace bindings from the schema document.
> >
> > What do you think?
> >
> > Thanks.
> >
> > [1]
> > http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/
> XPath.html#compile(java.lang.String)
> > [2]
> > http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/
> XPathExpression.html#evaluate(java.lang.Object)
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   This seems to be a very nice idea.

Presently, the assertions XPath expressions are compiled each time an
assertion is evaluated. As you rightly explained, this looks certainly
expensive (and infact I feel, this can become quite expensive for
large XML trees with repeating XML fragments, whose XSD types may
define assertions).

The optimization you have suggested seems doable and looks even
conceptually simple to implement.

I think, we can store the complied assert XPath expression, in
XPath20Assert.java where we are presently keeping a XPath string
representation. This new design looks to me, a quite optimized
implementation, and would likely save a significant runtime cost.

It looks to me that, it might be easier to store the XSD namespace
prefix in the object, XSAssertImpl. We can populate this information
while performing the assertions traversal actions on the XSD simple
and complex types. This looks achievable to me.

Can I begin doing these improvements? Any more suggestions regarding
these issues, would be great :)

On Fri, Nov 13, 2009 at 11:41 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I had a deeper look at what's currently in SVN and it's quite different than
> what I would have expected to see, perhaps in part due to the design of
> PsychoPath. I was hoping to find a separation between the parsing /
> processing of the XPath expressions and their evaluation during schema
> validation, with the work for the XPath parsing / processing being done once
> during schema loading (or deferred until it's actually needed). This is a
> pattern supported by the JAXP XPath API, where you compile [1] an XPath
> expression and use / reuse this compiled expression for evaluation [2] many
> times. The compilation step is potentially expensive but you only pay for
> this cost once.
>
> It seems that we pay for the XPath parsing every time we evaluate an
> expression. I can't imagine that would have good performance. I'm hoping
> that there's a better way of doing this where the parsing of the XPath
> expression is done during schema loading which is also the best place to be
> pulling the namespace bindings from the schema document.
>
> What do you think?
>
> Thanks.
>
> [1]
> http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPath.html#compile(java.lang.String)
> [2]
> http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPathExpression.html#evaluate(java.lang.Object)
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

I had a deeper look at what's currently in SVN and it's quite different
than what I would have expected to see, perhaps in part due to the design
of PsychoPath. I was hoping to find a separation between the parsing /
processing of the XPath expressions and their evaluation during schema
validation, with the work for the XPath parsing / processing being done
once during schema loading (or deferred until it's actually needed). This
is a pattern supported by the JAXP XPath API, where you compile [1] an
XPath expression and use / reuse this compiled expression for evaluation
[2] many times. The compilation step is potentially expensive but you only
pay for this cost once.

It seems that we pay for the XPath parsing every time we evaluate an
expression. I can't imagine that would have good performance. I'm hoping
that there's a better way of doing this where the parsing of the XPath
expression is done during schema loading which is also the best place to be
pulling the namespace bindings from the schema document.

What do you think?

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPath.html#compile
(java.lang.String)
[2]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/xpath/XPathExpression.html#evaluate
(java.lang.Object)

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/12/2009 06:56:55 AM:

> Hi Michael,
>    I think, I need to get XSD namespace prefix within
> XMLSchemaValidator, so that I can pass it to the PsychoPath interface.
>
> To get the XSD namespace prefix, I was thinking to somehow access the
> XSDocumentInfo object within XMLSchemaValidator.java. Getting XSD
> namespace prefix from XSDocumentInfo is possible via, the object
> "protected Element fSchemaElement", which is the root of XSD document
> tree.
>
> But looking at the Xerces code for a while, I cannot find a means to
> get access to XSDocumentInfo object from within XMLSchemaValidator.
>
> Could you please suggest, what will be the correct approach to do this
> (i.e, accessing XSD namespace prefix from within XMLSchemaValidator)?
>
> On Thu, Nov 12, 2009 at 2:35 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > Hi Mukul,
> >
> > As you've noted "http://www.w3.org/2001/XMLSchema" can be bound to
other
> > prefixes than "xs".  Also, "xs" could be bound to something other than
> > "http://www.w3.org/2001/XMLSchema" or not be declared at all.
> >
> > We should not be hard-coding the namespace bindings. For each XPath
> > expression they should be determined from the namespace context of the
> > schema we're processing and I believe also the and the
> > "xpathDefaultNamespace" attribute which might be on the "assertion" or
> > "schema" element if the assertion doesn't have one. Doing anything else
is
> > incorrect.
> >
> > Thanks.
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   I think, I need to get XSD namespace prefix within
XMLSchemaValidator, so that I can pass it to the PsychoPath interface.

To get the XSD namespace prefix, I was thinking to somehow access the
XSDocumentInfo object within XMLSchemaValidator.java. Getting XSD
namespace prefix from XSDocumentInfo is possible via, the object
"protected Element fSchemaElement", which is the root of XSD document
tree.

But looking at the Xerces code for a while, I cannot find a means to
get access to XSDocumentInfo object from within XMLSchemaValidator.

Could you please suggest, what will be the correct approach to do this
(i.e, accessing XSD namespace prefix from within XMLSchemaValidator)?

On Thu, Nov 12, 2009 at 2:35 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> As you've noted "http://www.w3.org/2001/XMLSchema" can be bound to other
> prefixes than "xs".  Also, "xs" could be bound to something other than
> "http://www.w3.org/2001/XMLSchema" or not be declared at all.
>
> We should not be hard-coding the namespace bindings. For each XPath
> expression they should be determined from the namespace context of the
> schema we're processing and I believe also the and the
> "xpathDefaultNamespace" attribute which might be on the "assertion" or
> "schema" element if the assertion doesn't have one. Doing anything else is
> incorrect.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

Given that the default behaviour of PsychoPath (for the default function
namespace) matches what XML Schema 1.1 requires I won't worry about it.

Thanks for clearing this up.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/13/2009 12:17:03 AM:

> Hi Michael,
>
> On Fri, Nov 13, 2009 at 9:57 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > That is the part that still doesn't make sense to me. How is PsychoPath
> > determining what the "default function namespace" is? Magic? :-) We
don't
> > set it anywhere.
>
> The "default function namespace" is set to
> http://www.w3.org/2005/xpath-functions by default in PsychoPath. I am
> currently not sure, if PsychoPath can override this default via some
> API of it's own. If it can override this default, I am not sure, what
> it needs to do with any other default function namespace. I need to
> check this with the PsychoPath team. I can get back with an answer to
> this, after some time.
>
> But for now, this doesn't seem to be problem for Xerces-J, as we are
> able to comply to XSD 1.1 spec, with this particular feature of
> PsychoPath.
>
> > Put another way, if XML Schema provided a way for users to specify the
> > default function namespace (e.g. another attribute like
> > xpathDefaultNamespace but applies to function names instead of element
> > names) how could you set it with PsychoPath? Is this something that's
> > missing from its API?
>
> I think, ability to set any arbitrary "default function namespace" is
> presently missing in PsychoPath. The default function namespace is
> presently hard coded as, http://www.w3.org/2005/xpath-functions in
> PsychoPath, and it seems to me that it cannot be overridden via some
> PsychoPath API.
>
> But it seems to me, this doesn't affect Xerces-J presently. User's
> certainly seem to be unaffected by this PsychoPath feature, while
> writing XSD 1.1 schemas.
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,

On Fri, Nov 13, 2009 at 9:57 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> That is the part that still doesn't make sense to me. How is PsychoPath
> determining what the "default function namespace" is? Magic? :-) We don't
> set it anywhere.

The "default function namespace" is set to
http://www.w3.org/2005/xpath-functions by default in PsychoPath. I am
currently not sure, if PsychoPath can override this default via some
API of it's own. If it can override this default, I am not sure, what
it needs to do with any other default function namespace. I need to
check this with the PsychoPath team. I can get back with an answer to
this, after some time.

But for now, this doesn't seem to be problem for Xerces-J, as we are
able to comply to XSD 1.1 spec, with this particular feature of
PsychoPath.

> Put another way, if XML Schema provided a way for users to specify the
> default function namespace (e.g. another attribute like
> xpathDefaultNamespace but applies to function names instead of element
> names) how could you set it with PsychoPath? Is this something that's
> missing from its API?

I think, ability to set any arbitrary "default function namespace" is
presently missing in PsychoPath. The default function namespace is
presently hard coded as, http://www.w3.org/2005/xpath-functions in
PsychoPath, and it seems to me that it cannot be overridden via some
PsychoPath API.

But it seems to me, this doesn't affect Xerces-J presently. User's
certainly seem to be unaffected by this PsychoPath feature, while
writing XSD 1.1 schemas.



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

Mukul Gandhi <mu...@apache.org> wrote on 11/12/2009 11:09:24 PM:

<snip/>

> You rightly said, that XPath 2 static context should provide a
> "Default function namespace" binding as well (described at this link
> which you cited, http://www.w3.org/TR/xpath20/#dt-def-fn-ns). To
> answer your following questions:
>
> <question>
> XPath 2.0 processor should allow you to set it to anything, so can't
> see how it could be working correctly without having code somewhere in
> Xerces which explicitly sets that on PsychoPath.
>
> In other words a call like:
>
> fDynamicContext.set_default_function_namespace("http://www.w3.org/
> 2005/xpath-functions");
>
> or whatever the method is in PsychoPath for specifying it.
> </question>
>
> This can be achieved by simply not specifying any namespace binding
> for the URI http://www.w3.org/2005/xpath-functions in Xerces-J java
> code.
>
> i.e, simply removing this method call in, AbstractPsychoPathImpl.java
>
> fDynamicContext.add_namespace("fn",
"http://www.w3.org/2005/xpath-functions");
>
> will fix this issue. This statement simply needs to be removed, to
> comply to the spec, as you stated. So the fix for this problem, seems
> to be very trivial :)

That is the part that still doesn't make sense to me. How is PsychoPath
determining what the "default function namespace" is? Magic? :-) We don't
set it anywhere.

Put another way, if XML Schema provided a way for users to specify the
default function namespace (e.g. another attribute like
xpathDefaultNamespace but applies to function names instead of element
names) how could you set it with PsychoPath? Is this something that's
missing from its API?

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   I'll try to explain your query from following perspectives:

XPath 2.0 language,
XPath 2 F&O spec &
XSD 1.1 language

And how PsychoPath supports the XPath 2 F&O namespace, and how a host
language (like XSD 1.1 or even Java) should handle XPath 2 F&O
namespace.

I think, the Java code in Xerces-J should not be relevant here, as the
host language for XPath 2 function calls here is (i.e, XPath 2
function calls in assertion XPath 2 expressions), the XSD 1.1 Schema
language (and not the Java code which is written within Xerces-J).

The XPath 2.0 F&O specs defines, that all built in XPath 2 functions
exist with the XML namespace, http://www.w3.org/2005/xpath-functions
(ref, http://www.w3.org/TR/xpath-functions/#namespace-prefixes). A
conforming XPath 2 engine has to statically bind this F&O namespace
URI to all the built in XPath 2 implementation code. PsychoPath
correctly does this.

Here are some PsychoPath internals, which are relevant to this discussion:
PsychoPath engine allows a host language (like say a Java program.
Here Xerces-J code plays that role) to create namespace bindings (in
the XPath 2 static context) for PsychoPath, which are available at
runtime. PsychoPath provides a method, "add_namespace" in the
PsychoPath inteface StaticContext. "add_namespace" method is also
exposed to PsychoPath interface DynamicContext, as also reflected in
the code in Xerces class, AbstractPsychoPathImpl.java. This works
because, PsychoPath internally does something like, "public interface
DynamicContext extends StaticContext".

You rightly said, that XPath 2 static context should provide a
"Default function namespace" binding as well (described at this link
which you cited, http://www.w3.org/TR/xpath20/#dt-def-fn-ns). To
answer your following questions:

<question>
XPath 2.0 processor should allow you to set it to anything, so can't
see how it could be working correctly without having code somewhere in
Xerces which explicitly sets that on PsychoPath.

In other words a call like:

fDynamicContext.set_default_function_namespace("http://www.w3.org/2005/xpath-functions");

or whatever the method is in PsychoPath for specifying it.
</question>

This can be achieved by simply not specifying any namespace binding
for the URI http://www.w3.org/2005/xpath-functions in Xerces-J java
code.

i.e, simply removing this method call in, AbstractPsychoPathImpl.java

fDynamicContext.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");

will fix this issue. This statement simply needs to be removed, to
comply to the spec, as you stated. So the fix for this problem, seems
to be very trivial :)

I think, we should also provide a facility in Xerces-J where by if we
bind the XPath 2 F&O namespace URI on xs:schema element (say for e.g,
like <xs:schema xmlns:fn="http://www.w3.org/2005/xpath-functions"
...), then a Xerces-J component like AbstractPsychoPathImpl.java
should create namespace binding for URI
http://www.w3.org/2005/xpath-functions with prefix "fn", as for this
example (or whatever this prefix is, as defined on xs:schema element).
i.e, AbstractPsychoPathImpl should not hardcode any namespace binding
for URI, http://www.w3.org/2005/xpath-functions. But instead should
create a binding only if, a namespce declaration is present on
xs:schema. I think, this can be technically implemented by the
solution that we will arrive at, for the XSD 1.1 prefix that we are
discussing just now.

I hope this response is clear enough, and could answer your queries.

Please let us know, if something is still missing.

On Thu, Nov 12, 2009 at 9:31 PM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I'm afraid I don't follow how that could work. I see nothing in the code
> which sets the default function namespace [1] to be
> "http://www.w3.org/2005/xpath-functions". XML Schema 1.1 [2] fixes its value
> to be "http://www.w3.org/2005/xpath-functions", but an XPath 2.0 processor
> should allow you to set it to anything, so can't see how it could be working
> correctly without having code somewhere in Xerces which explicitly sets that
> on PsychoPath.
>
> In other words a call like:
>
> fDynamicContext.set_default_function_namespace("http://www.w3.org/2005/xpath-functions");
>
> or whatever the method is in PsychoPath for specifying it.
>
> Thanks.
>
> [1] http://www.w3.org/TR/xpath20/#dt-def-fn-ns
> [2] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-xpath-valid
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

I'm afraid I don't follow how that could work. I see nothing in the code
which sets the default function namespace [1] to be
"http://www.w3.org/2005/xpath-functions". XML Schema 1.1 [2] fixes its
value to be "http://www.w3.org/2005/xpath-functions", but an XPath 2.0
processor should allow you to set it to anything, so can't see how it could
be working correctly without having code somewhere in Xerces which
explicitly sets that on PsychoPath.

In other words a call like:

fDynamicContext.set_default_function_namespace
("http://www.w3.org/2005/xpath-functions");

or whatever the method is in PsychoPath for specifying it..

Thanks.

[1] http://www.w3.org/TR/xpath20/#dt-def-fn-ns
[2] http://www.w3.org/TR/2009/CR-xmlschema11-1-20090430/#sec-xpath-valid

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com);
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/12/2009 10:37:59 AM:

> Hi Michael,
>    Kindly see my replies inline, please.
>
> On Thu, Nov 12, 2009 at 8:08 PM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > Well, it's a problem if we're interpreting "fn" as something it's not.
It
> > could be bound to another namespace or none at all.
>
> You have explained this correctly.
>
> >> string(test) eq 'xxx'
> >
> > Does this work today?
>
> Yes, it does. All built in XPath 2.0 functions work fine when invoked
> like above (i.e, without specifying any prefix to built in XPath 2
> function calls), with PsychoPath and Xerces assertions. This works ok
> with the current Xerces SVN code. That's good according to me.
>
> > Searching for "http://www.w3.org/2005/xpath-functions"
> > in the code I couldn't see where it is being set as the default
function
> > namespace. Is this supported by PsychoPath?
>
> Yes, this namespace is supported by PsychoPath. This namespace is
> defined in XPath 2.0 F&O spec (ref,
> http://www.w3.org/TR/xpath-functions/#namespace-prefixes).
>
> This XPath 2 F&O namespace URI is enforced in Xerces code in the
> class, AbstractPsychoPathImpl.java with this statement:
>
> fDynamicContext.add_namespace("fn",
"http://www.w3.org/2005/xpath-functions");
>
>
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   Kindly see my replies inline, please.

On Thu, Nov 12, 2009 at 8:08 PM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Well, it's a problem if we're interpreting "fn" as something it's not. It
> could be bound to another namespace or none at all.

You have explained this correctly.

>> string(test) eq 'xxx'
>
> Does this work today?

Yes, it does. All built in XPath 2.0 functions work fine when invoked
like above (i.e, without specifying any prefix to built in XPath 2
function calls), with PsychoPath and Xerces assertions. This works ok
with the current Xerces SVN code. That's good according to me.

> Searching for "http://www.w3.org/2005/xpath-functions"
> in the code I couldn't see where it is being set as the default function
> namespace. Is this supported by PsychoPath?

Yes, this namespace is supported by PsychoPath. This namespace is
defined in XPath 2.0 F&O spec (ref,
http://www.w3.org/TR/xpath-functions/#namespace-prefixes).

This XPath 2 F&O namespace URI is enforced in Xerces code in the
class, AbstractPsychoPathImpl.java with this statement:

fDynamicContext.add_namespace("fn", "http://www.w3.org/2005/xpath-functions");


> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org


-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

Mukul Gandhi <mu...@apache.org> wrote on 11/11/2009 10:30:23 PM:

> Hi Michael,
>    I agree with you, that hard coding the prefix "fn" for XPath 2.0
> F&O namespace (http://www.w3.org/2005/xpath-functions) in Xerces, is
> also not correct.
>
> But the problem with prefix "fn" in Xerces is not a problem that will
> affect users, as users can use XPath 2.0 built in functions in
> assertion XPath 2 expressions without specifying any prefix.

Well, it's a problem if we're interpreting "fn" as something it's not. It
could be bound to another namespace or none at all.,

> For e.g, following assertion XPath expression would work fine with
Xerces-J:
>
> string(test) eq 'xxx'

Does this work today? Searching for "http://www.w3.org/2005/xpath-functions
" in the code I couldn't see where it is being set as the default function
namespace. Is this supported by PsychoPath?

> But following expression would also work fine as well [1]:
>
> fn:string(test) eq 'xxx'
>
> But for expression [1] to work, the prefix "fn" need not be declared
> on the XSD 1.1 "xs:schema" element. That looks ironical.
>
> The prefix "fn" at present is redundant for Xerces assertion XPath
> expressions. Users should simply not use the prefix "fn" (while using
> XPath 2.0 built in functions) in assertion XPath 2 expressions, and
> everything would work fine.
>
> But you rightly pointed, that this is redundant and we must remove
> "fn" prefix reference from Xerces code. Also, if users try to use
> prefix "fn" for any other purpose related to their proprietary use,
> then F&O prefix "fn" would certainly cause confusion. So it looks to
> me as well, that this should be corrected.
>
> I'll try to do this as well, as I am doing the XSD namespace prefix
> change for Xerces-PsychoPath interface.
>
> On Thu, Nov 12, 2009 at 5:47 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > Hi Mukul,
> >
> > I noticed in AbstractPsychoPathImpl that the "fn" prefix is also being
given
> > special treatment. I believe that we should not be hard-coding that
either.
> >
> > Thanks.
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   I agree with you, that hard coding the prefix "fn" for XPath 2.0
F&O namespace (http://www.w3.org/2005/xpath-functions) in Xerces, is
also not correct.

But the problem with prefix "fn" in Xerces is not a problem that will
affect users, as users can use XPath 2.0 built in functions in
assertion XPath 2 expressions without specifying any prefix.

For e.g, following assertion XPath expression would work fine with Xerces-J:

string(test) eq 'xxx'

But following expression would also work fine as well [1]:

fn:string(test) eq 'xxx'

But for expression [1] to work, the prefix "fn" need not be declared
on the XSD 1.1 "xs:schema" element. That looks ironical.

The prefix "fn" at present is redundant for Xerces assertion XPath
expressions. Users should simply not use the prefix "fn" (while using
XPath 2.0 built in functions) in assertion XPath 2 expressions, and
everything would work fine.

But you rightly pointed, that this is redundant and we must remove
"fn" prefix reference from Xerces code. Also, if users try to use
prefix "fn" for any other purpose related to their proprietary use,
then F&O prefix "fn" would certainly cause confusion. So it looks to
me as well, that this should be corrected.

I'll try to do this as well, as I am doing the XSD namespace prefix
change for Xerces-PsychoPath interface.

On Thu, Nov 12, 2009 at 5:47 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> I noticed in AbstractPsychoPathImpl that the "fn" prefix is also being given
> special treatment. I believe that we should not be hard-coding that either.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

I noticed in AbstractPsychoPathImpl that the "fn" prefix is also being
given special treatment. I believe that we should not be hard-coding that
either.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/11/2009 06:19:12 PM:

> Hi Michael,
>    Thanks for your reply, and confirming that this issue requires a fix.
>
> I'll be working to fix this one, with Xerces assertions and hoping to
> submit to Xerces forum asap, for evaluating the fix.
>
> I'll post any further questions related to this topic, in case I might
> have doubts.
>
> On Thu, Nov 12, 2009 at 2:35 AM, Michael Glavassevich
> <mr...@ca.ibm.com> wrote:
> > Hi Mukul,
> >
> > As you've noted "http://www.w3.org/2001/XMLSchema" can be bound to
other
> > prefixes than "xs".  Also, "xs" could be bound to something other than
> > "http://www.w3.org/2001/XMLSchema" or not be declared at all.
> >
> > We should not be hard-coding the namespace bindings. For each XPath
> > expression they should be determined from the namespace context of the
> > schema we're processing and I believe also the and the
> > "xpathDefaultNamespace" attribute which might be on the "assertion" or
> > "schema" element if the assertion doesn't have one. Doing anything else
is
> > incorrect.
> >
> > Thanks.
> >
> > Michael Glavassevich
> > XML Parser Development
> > IBM Toronto Lab
> > E-mail: mrglavas@ca.ibm.com
> > E-mail: mrglavas@apache.org
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org

Re: XML Schema prefix while using XPath expressions in assertions

Posted by Mukul Gandhi <mu...@apache.org>.
Hi Michael,
   Thanks for your reply, and confirming that this issue requires a fix.

I'll be working to fix this one, with Xerces assertions and hoping to
submit to Xerces forum asap, for evaluating the fix.

I'll post any further questions related to this topic, in case I might
have doubts.

On Thu, Nov 12, 2009 at 2:35 AM, Michael Glavassevich
<mr...@ca.ibm.com> wrote:
> Hi Mukul,
>
> As you've noted "http://www.w3.org/2001/XMLSchema" can be bound to other
> prefixes than "xs".  Also, "xs" could be bound to something other than
> "http://www.w3.org/2001/XMLSchema" or not be declared at all.
>
> We should not be hard-coding the namespace bindings. For each XPath
> expression they should be determined from the namespace context of the
> schema we're processing and I believe also the and the
> "xpathDefaultNamespace" attribute which might be on the "assertion" or
> "schema" element if the assertion doesn't have one. Doing anything else is
> incorrect.
>
> Thanks.
>
> Michael Glavassevich
> XML Parser Development
> IBM Toronto Lab
> E-mail: mrglavas@ca.ibm.com
> E-mail: mrglavas@apache.org



-- 
Regards,
Mukul Gandhi

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


Re: XML Schema prefix while using XPath expressions in assertions

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

As you've noted "http://www.w3.org/2001/XMLSchema" can be bound to other
prefixes than "xs".  Also, "xs" could be bound to something other than
"http://www.w3.org/2001/XMLSchema" or not be declared at all.

We should not be hard-coding the namespace bindings. For each XPath
expression they should be determined from the namespace context of the
schema we're processing and I believe also the and the
"xpathDefaultNamespace" attribute which might be on the "assertion" or
"schema" element if the assertion doesn't have one. Doing anything else is
incorrect.

Thanks.

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Mukul Gandhi <mu...@apache.org> wrote on 11/11/2009 04:44:12 AM:

> Hi all,
>    We specify XSD 1.1 Schema, and a sample assertions something like
below:
>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
>    ...
>    <xs:assert test="xs:string(test) eq 'xxx'" />
>    ...
> </xs:schema>
>
> The current implementation of XSD 1.1 assertions within Xerces-J,
> while invoking the PsychoPath XPath 2.0 engine, constructs a namespace
> binding in a kind of map (actually Xerces-J adds all the needed
> namespace definitions for PsychoPath, in a XPath 2.0 "DynamicContext"
> object), that is passed to the PsychoPath engine, while doing an XPath
> 2 evaluation.
>
> One of the namespace bindings that Xerces-J initializes for PsychoPath
> is the XML Schema namespace. This is done as following, with an
> PsychoPath API:
>
> DynamicContext.add_namespace("xs", "http://www.w3.org/2001/XMLSchema");
>
> This is an important namespace binding, that Xerces-J has to
> initialize for XPath 2 evaluation with PsychoPath.
>
> The prefix "xs" is presently hardcoded in Xerces-J, which means that
> presently only this particular prefix can be functionally used while
> evaluating XPath expressions, with PsychoPath. This has significance,
> when we use any constructs from the XML Schema namespace, like say
> xs:string in assertion XPath 2.0 expressions.
>
> For the above XSD 1.1 example, the assertion would evaluate fine as
> expected (because the prefix "xs" was used in XPath 2 expression. And
> ironically, Xerces-J currently does not enforce statically the binding
> between prefix "xs" in assertion XPath expressions and the Schema
> namespace URI that is defined on xs:schema element. Is this an
> important issue to look at?). But following assertions would fail (it
> would return false), if written in the XSD 1.1 schema:
>
> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
>   ...
>   <xsd:assert test="xsd:string(test) eq 'xxx'" />
>
> (because the XPath expression in assertions uses the prefix "xsd" for
> XML schema. But the whole XSD 1.1 schema looks correct.)
>
> Currently, Xerces-J plus PsychoPath engine cannot utilize any other
> XSD prefix (than, "xs") for assertion XPath 2 expressions. The problem
> happens for following expression, in above XSD 1.1 Schema:
>
> xsd:string(test) eq 'xxx'
>
> While rest of Schema would execute fine.
>
> So presently, a convention (i.e, prefix "xs" for namespace
> http://www.w3.org/2001/XMLSchema) controls the XPath expressions that
> are evaluated by PsychoPath engine.
>
> Ideally, I would wish that Xerces-J can create a XML Schema namespace
> binding for PsychoPath engine as following:
>
> DynamicContext.add_namespace("xx", "http://www.w3.org/2001/XMLSchema");
>
> Where, the XSD prefix string "xx" would be read dynamically from the
> actual XSD Schema at runtime.
>
> Should something like this must be done, to support assertions? If
> yes, an advise on the design for this would be helpful.
>
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-dev-help@xerces.apache.org