…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&apos;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&apos;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@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&apos;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&apos;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@architextus.com
> (514) 572-0341
>
> _______________________________________________
> BaseX-Talk mailing list
> BaseX-Talk@mailman.uni-konstanz.de
> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
>