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
Hi Alex,
the streaming module (introduced with the 7.7 beta) may do what you need:
http://docs.basex.org/wiki/Streaming_Module
You can also use the data(...) function in order to ensure that your query result will be materialized.
Feel free to ask for more, Christian ___________________________
2013/6/11 Alexander von Bernuth alexander.von-bernuth@student.uni-tuebingen.de:
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
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
…what I forgot: all errors of the Fetch Module belong to the "http://basex.org/errors" namespace, which is statically bound to the "bxerr" prefix [1]:
try { data(...) } catch bxerr:BXFE0001 { ... }
For testing, and to catch all other errors, you can also use * as wildcard.
Best, Christian
[1] http://docs.basex.org/wiki/Fetch_Module ___________________________
2013/6/11 Christian Grün christian.gruen@gmail.com:
Hi Alex,
the streaming module (introduced with the 7.7 beta) may do what you need:
http://docs.basex.org/wiki/Streaming_Module
You can also use the data(...) function in order to ensure that your query result will be materialized.
Feel free to ask for more, Christian ___________________________
2013/6/11 Alexander von Bernuth alexander.von-bernuth@student.uni-tuebingen.de:
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
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de