DTD validation
Tuesday, 18 December 2012 · 4 messages · last reply 19 Dec 2012
CG
Hi France,
just a short one for today.. did you try to enclose your validate function with try/catch?
Christian
Quoted text · France Baril · 74 lines
Am 18.12.2012 01:40 schrieb "France Baril" <france.baril at architextus.com>: > Hi, > > We are having challenges with validation. > > We have built a Documentation Controller for authors that create XML > content. On a regular basis, we ask them to check that all documents are > valid. We are running the process on hundreds of file. the ideal situation > would be to collect all errors and display them of the webpage for authors > to find and correct. > > Ex. of dream code: > > *let **$db* := *app:open-db*(*$lang*) > *let* *$topic-validation* := <ul>{*for **$x* *in **$db*/*[* > name*()='topic' or *name*()='media'] > *return if* (*contains*(* > validate:dtd*(*$x*, *$app:dtd-topic*), 'BXVA0001')) > > *then *<li>File {*$x*/ > *base-uri*()} doesn't validate against the DTD.</li> > *else *() > > } > </ul> > > *let* *$menu-validation* := <ul>{*for **$x* *in **$db*/*[* > name*()='menu'] > *return if* (*contains*(* > validate:dtd*(*$x*, *$app:dtd-menu*), 'BXVA0001')) > > *then *<li>File {*$x*/ > *base-uri*()} doesn't validate against the DTD.</li> > *else *() > }</ul> > > > *return if* (*count*(*$topic-validation*/*li*) + *count*(* > $menu-validation*/*li*[*normalize-space*(.) != '']) != 0) > *then *<div>{*$topic-validation*}{*$menu-validation* > }</div> > *else *<ul><li *style*=*"color:green"*>All menus > and topics validate against the DTDs.</li></ul> > > Instead, as soon as validate:dtd finds one single file with an error, it > crashes the web page with an error message like this: > > > > Stopped at line 270, column 77 in /Applications/basex75/webapp/restxq/How2_Admin.xqm: > [BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type "headin" must be declared. > > On top of this, the name of the file that is referenced in the error message doesn't exist. > > I've been querying the DB to find errors. Ex. Search for all files with 'headin' in this case. However, we'd really like the writer to be able to find their own faulty files. > > Are we misusing the function? Is this a bug? What can we do about it? > > > Thanks in advance for you help! > > > -- > France Baril > Architecte documentaire / Documentation architect > france.baril at architextus.com > (514) 572-0341 > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
FB
France Baril18 Dec 2012 02:39 #
Hi,
We are having challenges with validation.
We have built a Documentation Controller for authors that create XML content. On a regular basis, we ask them to check that all documents are valid. We are running the process on hundreds of file. the ideal situation would be to collect all errors and display them of the webpage for authors to find and correct.
Ex. of dream code:
*let **$db* := *app:open-db*(*$lang*)
*let* *$topic-validation* := <ul>{*for **$x* *in **$db*/*[*
name*()='topic' or *name*()='media']
*return if* (*contains*(*
validate:dtd*(*$x*, *$app:dtd-topic*), 'BXVA0001'))
*then *<li>File {*$x*/*
base-uri*()} doesn't validate against the DTD.</li>
*else *()
}
</ul> *let* *$menu-validation* := <ul>{*for **$x* *in **$db*/*[* name*()='menu']
*return if* (*contains*(*
validate:dtd*(*$x*, *$app:dtd-menu*), 'BXVA0001')) *then *<li>File {*$x*/*
base-uri*()} doesn't validate against the DTD.</li>
*else *()
}</ul>
*return if* (*count*(*$topic-validation*/*li*) + *count*(*
$menu-validation*/*li*[*normalize-space*(.) != '']) != 0)
*then *<div>{*$topic-validation*}{*$menu-validation*}
</div>
*else *<ul><li *style*=*"color:green"*>All menus and
topics validate against the DTDs.</li></ul>Instead, as soon as
validate:dtd finds one single file with an error, it crashes the web page with an error message like this:
Stopped at line 270, column 77 in
/Applications/basex75/webapp/restxq/How2_Admin.xqm:
[BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type "headin" must be declared.
On top of this, the name of the file that is referenced in the error message doesn't exist.
I've been querying the DB to find errors. Ex. Search for all files with 'headin' in this case. However, we'd really like the writer to be able to find their own faulty files.
Are we misusing the function? Is this a bug? What can we do about it?
Thanks in advance for you help!--
France Baril
Architecte documentaire / Documentation architect
france.baril at architextus.com
(514) 572-0341
CG
Christian Grün18 Dec 2012 14:09 #
…and a longer one: the attached query may do what you need.
Quoted text · France Baril · 5 lines
> Stopped at line 270, column 77 in > /Applications/basex75/webapp/restxq/How2_Admin.xqm: > [BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type "headin" > must be declared.
In the validation process, your xml file is temporarily stored to disk, and 1355790115420.xml was the assigned file name. We may remove this information from the error message, as it’s indeed confusing.
Hope this helps,
Christian
The rewritten query (I didn’t try it live):
let $db := app:open-db($lang)
let $topic-validation := <ul>{
for $x in $db/*[name() = ('topic', 'media')]
return try {
validate:dtd($x, $app:dtd-topic)
} catch bxerr:BXVA0001 {
<li>File {$x/base-uri()} doesn't validate against the DTD.</li>
}
}
</ul>
let $menu-validation := <ul>{
for $x in $db/*[name() = 'menu']
return try {
validate:dtd($x, $app:dtd-menu)
} catch bxerr:BXVA0001 {
<li>File {$x/base-uri()} doesn't validate against the DTD.</li>
}
return
if($topic-validation or $menu-validation)
then <div>{$topic-validation}{$menu-validation}</div>
else <ul><li style="color:green">All menus and topics validate against
the DTDs.</li></ul>Quoted text · France Baril · 78 lines
On Tue, Dec 18, 2012 at 1:39 AM, France Baril <france.baril at architextus.com> wrote: > Hi, > > We are having challenges with validation. > > We have built a Documentation Controller for authors that create XML > content. On a regular basis, we ask them to check that all documents are > valid. We are running the process on hundreds of file. the ideal situation > would be to collect all errors and display them of the webpage for authors > to find and correct. > > Ex. of dream code: > > let $db := app:open-db($lang) > let $topic-validation := <ul>{for $x in $db/*[name()='topic' > or name()='media'] > return if > (contains(validate:dtd($x, $app:dtd-topic), 'BXVA0001')) > then <li>File > {$x/base-uri()} doesn't validate against the DTD.</li> > else () > > } > </ul> > > let $menu-validation := <ul>{for $x in $db/*[name()='menu'] > return if > (contains(validate:dtd($x, $app:dtd-menu), 'BXVA0001')) > then <li>File > {$x/base-uri()} doesn't validate against the DTD.</li> > else () > }</ul> > > > return if (count($topic-validation/li) + > count($menu-validation/li[normalize-space(.) != '']) != 0) > then <div>{$topic-validation}{$menu-validation}</div> > else <ul><li style="color:green">All menus and topics > validate against the DTDs.</li></ul> > > > Instead, as soon as validate:dtd finds one single file with an error, it > crashes the web page with an error message like this: > > Stopped at line 270, column 77 in > /Applications/basex75/webapp/restxq/How2_Admin.xqm: > [BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type "headin" > must be declared. > > On top of this, the name of the file that is referenced in the error message > doesn't exist. > > I've been querying the DB to find errors. Ex. Search for all files with > 'headin' in this case. However, we'd really like the writer to be able to > find their own faulty files. > > Are we misusing the function? Is this a bug? What can we do about it? > > Thanks in advance for you help! > > > -- > France Baril > Architecte documentaire / Documentation architect > france.baril at architextus.com > (514) 572-0341 > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
FB
France Baril19 Dec 2012 00:15 #
I had tried it with the same bad result. Maybe I misused it because it works now.
Big thanks, this had been on my issue list for a long time! It makes my day!
On Tue, Dec 18, 2012 at 8:09 AM, Christian Grün
<christian.gruen at gmail.com>wrote:
Quoted text · Christian Grün · 130 lines
> …and a longer one: the attached query may do what you need. > > > Stopped at line 270, column 77 in > > /Applications/basex75/webapp/restxq/How2_Admin.xqm: > > [BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type > "headin" > > must be declared. > > In the validation process, your xml file is temporarily stored to disk, > and 1355790115420.xml was the assigned file name. We may remove this > information from the error message, as it’s indeed confusing. > > Hope this helps, > Christian > > The rewritten query (I didn’t try it live): > > let $db := app:open-db($lang) > let $topic-validation := <ul>{ > for $x in $db/*[name() = ('topic', 'media')] > return try { > validate:dtd($x, $app:dtd-topic) > } catch bxerr:BXVA0001 { > <li>File {$x/base-uri()} doesn't validate against the DTD.</li> > } > } > </ul> > > let $menu-validation := <ul>{ > for $x in $db/*[name() = 'menu'] > return try { > validate:dtd($x, $app:dtd-menu) > } catch bxerr:BXVA0001 { > <li>File {$x/base-uri()} doesn't validate against the DTD.</li> > } > > return > if($topic-validation or $menu-validation) > then <div>{$topic-validation}{$menu-validation}</div> > else <ul><li style="color:green">All menus and topics validate against > the DTDs.</li></ul> > > ___________________________ > > > On Tue, Dec 18, 2012 at 1:39 AM, France Baril < > france.baril at architextus.com> wrote: > > Hi, > > > > We are having challenges with validation. > > > > We have built a Documentation Controller for authors that create XML > > content. On a regular basis, we ask them to check that all documents are > > valid. We are running the process on hundreds of file. the ideal > situation > > would be to collect all errors and display them of the webpage for > authors > > to find and correct. > > > > Ex. of dream code: > > > > let $db := app:open-db($lang) > > let $topic-validation := <ul>{for $x in > $db/*[name()='topic' > > or name()='media'] > > return if > > (contains(validate:dtd($x, $app:dtd-topic), 'BXVA0001')) > > > then <li>File > > {$x/base-uri()} doesn't validate against the DTD.</li> > > else () > > > > } > > </ul> > > > > let $menu-validation := <ul>{for $x in > $db/*[name()='menu'] > > return if > > (contains(validate:dtd($x, $app:dtd-menu), 'BXVA0001')) > > > then <li>File > > {$x/base-uri()} doesn't validate against the DTD.</li> > > else () > > }</ul> > > > > > > return if (count($topic-validation/li) + > > count($menu-validation/li[normalize-space(.) != '']) != 0) > > then > <div>{$topic-validation}{$menu-validation}</div> > > else <ul><li style="color:green">All menus and > topics > > validate against the DTDs.</li></ul> > > > > > > Instead, as soon as validate:dtd finds one single file with an error, it > > crashes the web page with an error message like this: > > > > Stopped at line 270, column 77 in > > /Applications/basex75/webapp/restxq/How2_Admin.xqm: > > [BXVA0001] Validation failed: 1355790115420.xml, 3:22: Element type > "headin" > > must be declared. > > > > On top of this, the name of the file that is referenced in the error > message > > doesn't exist. > > > > I've been querying the DB to find errors. Ex. Search for all files with > > 'headin' in this case. However, we'd really like the writer to be able to > > find their own faulty files. > > > > Are we misusing the function? Is this a bug? What can we do about it? > > > > Thanks in advance for you help! > > > > > > -- > > France Baril > > Architecte documentaire / Documentation architect > > france.baril at architextus.com > > (514) 572-0341 > > > > _______________________________________________ > > BaseX-Talk mailing list > > BaseX-Talk at mailman.uni-konstanz.de > > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > > > >
--
France Baril
Architecte documentaire / Documentation architect
france.baril at architextus.com
(514) 572-0341
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery