Catching BXFE0001 when fetching binary

Tuesday, 11 June 2013 · 3 messages
AB
Alexander von Bernuth11 Jun 2013 15:00 #
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.
Quoted text · 19 lines
> 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
Quoted text · 4 lines
> [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 at student.uni-tuebingen.de
CG
Christian Grün11 Jun 2013 15:03 #
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 at student.uni-tuebingen.de>:
Quoted text · Alexander von Bernuth · 69 lines
> 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 at student.uni-tuebingen.de > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >
CG
Christian Grün11 Jun 2013 15:10 #
…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 at gmail.com>:
Quoted text · Christian Grün · 84 lines
> 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 at 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 at student.uni-tuebingen.de >> >> >> _______________________________________________ >> BaseX-Talk mailing list >> BaseX-Talk at mailman.uni-konstanz.de >> https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk >>

⚡Generated with XQuery