Tuesday, January 26, 2010

Xpath

XPath uses path expressions to select nodes or node-sets in an XML document.
It contains a library of standard functions and is a major element in XSLT .A W3C recommendation


Several Path Expression Result
//book/title | //book/price Selects all the title AND price elements of all book elements
//title | //price Selects all the title AND price elements in the document
/bookstore/book/title | //price Selects all the title elements of the book element of the bookstore element AND all the price elements in the document


Wildcard Path Expression Result
/bookstore/* Selects all the child nodes of the bookstore element
//* Selects all elements in the document
//title[@*] Selects all title elements which have any attribute

Path Expression Result
/bookstore/book[1] Selects the first book element that is the child of the bookstore element.

Note: IE5 and later has implemented that [0] should be the first node, but according to the W3C standard it should have been [1]!!

/bookstore/book[last()] Selects the last book element that is the child of the bookstore element
/bookstore/book[last()-1] Selects the last but one book element that is the child of the bookstore element
/bookstore/book[position()<3] Selects the first two book elements that are children of the bookstore element
//title[@lang] Selects all the title elements that have an attribute named lang
//title[@lang='eng'] Selects all the title elements that have an attribute named lang with a value of 'eng'
/bookstore/book[price>35.00] Selects all the book elements of the bookstore element that have a price element with a value greater than 35.00
/bookstore/book[price>35.00]/title Selects all the title elements of the book elements of the bookstore element that have a price element with a value greater than 35.00



Ref:

w3schools
For trying xpath use try me
java xpath http://onjava.com/pub/a/onjava/2005/01/12/xpath.html

Thursday, January 14, 2010

RESTful.........what?

What is REST?
wiki says representational state transfer is a style of software architecture for distributed hypermedia systems..  The constraints described are :
  • Client Server
  • Stateless
  • Cacheable
  • Layered system
  • Code on demand
  • Uniform interface
RESTful web services (aka RESTful web API);
  Comprised of 3 aspects - URI, MIME type supported, operations supported using HTTP methods.

Public implementations : Atom publishing protocol, Suns cloud API etc

Arent all our web applications RESTful then?
So what does it mean for a java developer?
Answers here are quite close
http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/

Everything should be treated as a resouce on the web (not a page). The clear advantage of this is that the same URL can serve content in different formats. Currently most of the sites serve html pages, but they dont work on a mobile or a client expecting xml feeds,etc.

Think of REST as a sentence
• HTTP Methods are verbs
• URIs are nouns
• This grammar is currently being abused by existing websites.

Action implied in the URI
• Implied action conflicts with HTTP method
Conflicting
GET http://addressbook/contacts/destroy/1

Ref:
http://en.wikipedia.org/wiki/Representational_State_Transfer
http://www.rubyrailways.com/great-ruby-on-rails-rest-resources/