Hi,
I'm new to the Apache "experience" so please excuse
my ignorance.
I have been using the SchematronValidator portion
of Cocoon for validation of XML docs. I noticed that there was a problem in
specifying nested elements in the assert/report test statements - at least this
is the case when validating a DOMDocument - not sure about JavaBeans. After a
little inspection I found the fix for my problem (from email trail
below):
>It turns out that within the
SchematronValidator.evalRule method, if you change:
>
>JXPathContext localJxpContext =
JXPathContex.newContext(jxpContext, ptr.getValue());
>
>to:
>
>JXPPathConext localJxpContext =
jxpContext.getRelativeContext(ptr);
>
>(Note: ptr is a Pointer from an Iterator
obtained from the jxpContext)
>Then everything works OK for DOM documents -
butI haven't done any testing for JavaBeans....
I'm not sure how heavily this is exercised by
Cocoon users and my testing has been for my own specific purpose but the
SchematronValidator is certainly behaving as I require now for DOMDocuments. I
hope this fix is useful to others as I greatly appreciate the software I have
been able to obtain from Apache to date.
regards
Martin
----- Original Message -----
Sent: Tuesday, June 24, 2003 1:08 PM
Subject: Re: Using Cocoon's SchematronValidator
Martin,
Thank you very much for taking the time to investigate this
issue.
Lately, I have not been able to allocate as much time to
Cocoon as I would like to.
Please, forward this email to cocoon-dev and cocoon-user
lists.
I think it is worth promoting the fix at least to the level
where other people might be interested verifying it.
Cheers.
-=Ivelin=-
----- Original Message -----
Sent: Monday, June 23, 2003 8:25 AM
Subject: Re: Using Cocoon's
SchematronValidator
Hi Ivelin,
I had another look at the code rather than
posting of the question to the user lists.
It turns out that within the
SchematronValidator.evalRule method, if you change:
JXPathContext localJxpContext =
JXPathContex.newContext(jxpContext, ptr.getValue());
to:
JXPPathConext localJxpContext =
jxpContext.getRelativeContext(ptr);
(Note: ptr is a Pointer from an Iterator obtained
from the jxpContext)
Then everything works OK for DOM documents - butI
haven't done any testing for JavaBeans. The ptr.getValue() funtion for a
DOMNodePointer just returns the Node tree as a concatenated string value (as
the symptom described in my initial eamil), while the change I have suggested
returns a correct tree structured context.
Still very new to the whole Java/Apache
experience, so I'll leave it up to you as to whether this fix should be
promoted any further.
Thanks and regards
Martin Campbell
----- Original Message -----
Sent: Friday, June 20, 2003 3:01
PM
Subject: Re: Using Cocoon's
SchematronValidator
Martin,
I don't see a problem with your tests.
Please post your question to the JXPath (Jakarta Commons)
users list.
You may also consider posting on the Cocoon users in case
somebody else had this problem recently.
Regards,
-=Ivelin=-
----- Original Message -----
Sent: Thursday, June 19, 2003 11:48
PM
Subject: Using Cocoon's
SchematronValidator
Hi Ivelin,
I hope you don't mindme directing this email
personally I've had no response from the Schematron related mail
lists.
I am interested/attempting to use the Java
implementation of the Schematron contained in Cocoon for XML file semantic
validation, as opposed to XML web page validtion. I am loading the XML
file to be validated into a Dom object using
DOMParser.parseXML()
I am able to get the tests to run OK and may
own simple tests to run OK but there seems to be a problem when referring
to child nodes within the test attribute of an assert or report rule. As a
simple example, based on the following xml file:
<?xml
version="1.0"?> <things>
<animals>
<animal>
<name
version="1.1">cat</name>
<size>small</size>
</animal>
</animals>
<others>
<thing>
<name>car</name>
<size>medium</size>
</thing>
</others>
</things>
The following assert statement is
OK
<rule
context="/things/animals/animal[name='cat']/name/@version">
<assert test="string(.) =
'1.1'">Animal names should be at version
1.1</assert>
</rule>
But the following (and anyother attemp to use
a child node or attribute) fails
<rule
context="/things/animals/animal[name='cat']">
<assert test="string(name/@version) = '1.1'">Animal names
should be at version 1.1</assert>
</rule>
Looking at the code in
SchematronValidator.evalRule it would appear that the localJxpContext
generated looses all track of child nodes and attributes. Looking with a
debugger for the case above you would see a contextBean in the
loclJxpContext with a value of "catsmall".
Please excuse my ignorance in regards to
Java, still making the transition from C++.
Any assitance you could provide would be much
appreciated.
regards
Martin Campbell
By the way the following test
works:
<rule
context="/things/animals/animal[name='cat']">
<assert test="starts-with(.,
'cat')">Animal names should start with
cat!!</assert>
</rule>
|