Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Sunday, September 2, 2012

Wikimedia Commons queries to get image data

I am developing application to get images from Wikimedia Commons which is a big repository of excellent images. The query API is not well documented. I researched and came up with the following queries to get the file locations of images.

Suppose I want to get the images in the Category Flags of United States, I will do the following:

http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=categorymembers&cmlimit=10&cmtitle=Category:benthos

which produces the following XML output for the first 10 items.

<?xml version="1.0"?>
-<api>-<query>-<categorymembers><cm title="Category:Porifera" ns="14" pageid="13371"/><cm title="Category:Riftia pachyptila" ns="14" pageid="8805563"/><cm title="File:1991 benthos-achtern02 hg.jpg" ns="6" pageid="3321991"/><cm title="File:Abra alba.jpg" ns="6" pageid="333239"/><cm title="File:Ammonia tepida.jpg" ns="6" pageid="706636"/><cm title="File:Aonides paucibranchiata.jpg" ns="6" pageid="396315"/><cm title="File:Aphrodita aculeata (Sea mouse).jpg" ns="6" pageid="3610614"/><cm title="File:Aphrodita aculeata.jpg" ns="6" pageid="1525478"/><cm title="File:Arenicole système.jpg" ns="6" pageid="4258545"/><cm title="File:Asterias rubens.jpg" ns="6" pageid="364648"/></categorymembers></query>-<query-continue><categorymembers cmcontinue="file|42454e5448494320464f52414d494e4946455241532e4a5047|2080936"/></query-continue></api>


to  get an image you have to use the



http://commons.wikimedia.org/wiki/File:Aonides%20paucibranchiata.jpg will take you to the Aonides paucibranchiata image!



if you query

http://commons.wikimedia.org/w/api.php?format=xml&action=query&list=categorymembers&cmlimit=10&cmtitle=Category:benthos&cmcontinue=file|42454e5448494320464f52414d494e4946455241532e4a5047|2080936



you get the following output  which are the next 10 items, and so on



<?xml version="1.0"?>
-<api>-<query>-<categorymembers><cm title="File:Benthic foraminiferas.jpg" ns="6" pageid="2080936"/><cm title="File:Benthic GLERL 1.jpg" ns="6" pageid="2143998"/><cm title="File:Bentos kasarek.jpg" ns="6" pageid="16992357"/><cm title="File:Borstenwurmer des Meeres.png" ns="6" pageid="5229875"/><cm title="File:Branchiostoma lanceolatum.jpg" ns="6" pageid="5712836"/><cm title="File:Capitella capitata.jpg" ns="6" pageid="398359"/><cm title="File:Cirratulus cirratus.jpg" ns="6" pageid="398775"/><cm title="File:Crabmuss 600.jpg" ns="6" pageid="292191"/><cm title="File:Crangon crangon (dorsal).jpg" ns="6" pageid="10320338"/><cm title="File:Crangon crangon.jpg" ns="6" pageid="470098"/></categorymembers></query>-<query-continue><categorymembers cmcontinue="file|4352494252494e4f50534953204645524e414c44492e4a5047|3307271"/></query-continue></api>


Other useful formats



format=json



format=jsonfm produces a html output of json format.



Reference




  1. API reference


  2. API:Main page


  3. API:Tutorial

Tuesday, December 7, 2010

RSS feed XML source how to read

I was working with RSS and wanted to look at the source of the feed. Now all browsers have some sort of feed reader so it takes some effort. I normally use Opera to read xml documents. But to read RSS I has to use Internet explorer.

I followed the directions given in the article below.

IE 7 XML Feed Display & RSS Feed Validation

1) Click on the Tools menu,
2) Click on the Internet Options sub-menu,
3) Click on the Content tab,
4) Click on the Settings button of Feed section to bring up Feed Settings dialog box,
5) Un-tick the check-box of Turn On Feed Reading View option.
6) Click OK all the way to close all opened dialog boxes.

Another interesting article.

How To View RSS Feed In XML Format With Firefox

Saturday, October 2, 2010

Convert XML files to class files in Visual studio

xsd.exe gtest1.xsd  /cThese are the steps to convert xml files to class files in Visual Studio.

  1. Open the XML file in Visual Studio.
  2. Create Schema in the XML option.
  3. Run the Visual Studio command prompt from programs.
  4. Cd to the relevant file:
    1. cd C:\test1\test2\\xml_files
  5. To convert file
    1. xsd.exe test1.xsd  /c
  6. to convert multiple files
    1. xsd.exe test1.xsd test2.xsd  /c
  7. when converted individually lot of duplicate names had to be commented out.
  8. Easier approach use the XSD files create constructor for each item.