Hi folks,


I'm a student working on my bachelor thesis. I use BaseX to read large XML files and forward them to a PostgreSQL database. Additionally I want to fetch images via URI and add them to the database-records.
While fetching these images, I have to test three different file extensions for each image, as my source does not use one single image format (but jpg, png and gif).
First I tried checking with fn:doc-available($uri) weather that certain URI is available, but this obviously only works for XML-documents. Then I wanted to catch the err:BXFE0001 that is thrown by fetch:binary($uri), but this does not work, either; the error-message is displayed and the script stops.

  
declare variable $baseuri := 'http://www.bricklink.com/ML/';
declare variable $itemid := 'sw008';
  
try {
    fetch:binary($baseuri || $itemid || '.png')
}
catch err:BXFE0001 {
    try {
        fetch:binary($baseuri || $itemid || '.gif')
    }
    catch err:BXFE0001 {
        try {
            fetch:binary($baseuri || $itemid || '.jpg')
        }
        catch err:BXFE0001 {
            0
        }
    }
}

In this example, only the .jpg-image exists. But all I get is
  
[BXFE0001] Resource "http://www.bricklink.com/ML/sw008.png" not found.
Information:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The page cannot be found</TITLE> … and so on

I would be very glad if you could help me with this, either by pointing out my coding-error or by showing me another, better solution for doing this.


Thank you and have a nice day,
Alex

PS: My sources on Try/Catch and fetching


-- 
| Alexander von Bernuth
| alexander.von-bernuth@student.uni-tuebingen.de