Thursday, 20 March 2014

Xpath Expression Examples

Xpath Expression Examples

Xpath: It is syntax, used to navigate the elements and their attributes. Its make easy to get the any element or attribute.

XPath Terminology
1. element
2. attribute
3. text
4. namespace
5. processing-instruction
6. comment
7. document nodes

Following are few Xpath Expression and their Description
Xpath Expression Description
./writer All <writer> elements within the current context. Note that this is equivalent to the expression in the next row.
writer All <writer> elements within the current context.
first.name All <first.name> elements within the current context.
/bookStore The document element (<bookStore>) of this document.
//writer All <writer> elements in the document.
book[/bookStore/@specialty=@style] All <book> elements whose style attribute value is equal to the specialty attribute value of the <bookStore> element at the root of the document.
writer/first-name All <first-name> elements that are children of an <writer> element.
bookStore//title All <title> elements one or more levels deep in the <bookStore> element (arbitrary descendants). Note that this is different from the expression in the next row.
bookStore/*/title All <title> elements that are grandchildren of <bookStore> elements.
bookStore//book/excerpt//emph All <emph> elements anywhere inside <excerpt> children of <book> elements, anywhere inside the <bookStore> element.
.//title All <title> elements one or more levels deep in the current context. Note that this situation is essentially the only one in which the period notation is required.
writer/* All elements that are the children of <writer> elements.
book/*/lastName All <lastName> elements that are grandchildren of <book> elements.
*/* All grandchildren elements of the current context.
*[@specialty] All elements with the specialty attribute.
@style The style attribute of the current context.
price/@exchange The exchange attribute on <price> elements within the current context.
price/@exchange/total Returns an empty node set, because attributes do not contain element children. This expression is allowed by the XML Path Language (XPath) grammar, but is not strictly valid.
book[@style] All <book> elements with style attributes, of the current context.
book/@style The style attribute for all <book> elements of the current context.
@* All attributes of the current element context.
./first-name All <first-name> elements in the current context node. Note that this is equivalent to the expression in the next row.
first-name All <first-name> elements in the current context node.
writer[1] The first <writer> element in the current context node.
writer[first-name][3] The third <writer> element that has a <first-name> child.
my:book The <book> element from the my namespace.
my:* All elements from the my namespace.
@my:* All attributes from the my namespace (this does not include unqualified attributes on elements from the my namespace).
Note that indexes are relative to the parent. Consider the following data:

 

Xpath Expression Description
x/y[1] The first <y> child of each <x>. This is equivalent to the expression in the next row.
x/y[position() = 1] The first <y> child of each <x>.
(x/y)[1] The first <y> from the entire set of <y> children of <x> elements.
x[1]/y[2] The second <y> child of the first <x>.
 

 

Xpath Expression Description
book[last()] The last <book> element of the current context node.
book/writer[last()] The last <writer> child of each <book> element of the current context node.
(book/writer)[last()] The last <writer> element from the entire set of <writer> children of <book> elements of the current context node.
book[excerpt] All <book> elements that contain at least one <excerpt> element child.
book[excerpt]/title All <title> elements that are children of <book> elements that also contain at least one <excerpt> element child.
book[excerpt]/writer[degree] All <writer> elements that contain at least one <degree> element child, and that are children of <book> elements that also contain at least one <excerpt> element.
book[writer/degree] All <book> elements that contain <writer> children that in turn contain at least one <degree> child.
writer[degree][award] All <writer> elements that contain at least one <degree> element child and at least one <award> element child.
writer[degree and award] All <writer> elements that contain at least one <degree> element child and at least one <award> element child.
writer[(degree or award) and publication] All <writer> elements that contain at least one <degree> or <award> and at least one <publication> as the children
writer[degree and not(publication)] All <writer> elements that contain at least one <degree> element child and that contain no <publication> element children.
writer[not(degree or award) and publication] All <writer> elements that contain at least one <publication> element child and contain neither <degree> nor <award> element children.
writer[lastName = "Bob"] All <writer> elements that contain at least one <lastName> element child with the value Bob.
writer[lastName[1] = "Bob"] All <writer> elements where the first <lastName> child element has the value Bob. Note that this is equivalent to the expression in the next row.
writer[lastName [position()=1]= "Bob"] All <writer> elements where the first <lastName> child element has the value Bob.
degree[@from != "Harvard"] All <degree> elements where the from attribute is not equal to "Harvard".
writer[. = "Matthew Bob"] All <writer> elements whose value is Matthew Bob.
writer[lastName = "Bob" and ../price &gt; 50] All <writer> elements that contain a <lastName> child element whose value is Bob, and a <price> sibling element whose value is greater than 50.
book[position() &lt;= 3] The first three books (1, 2, 3).
writer[not(lastName = "Bob")] All <writer> elements that do no contain <lastName> child elements with the value Bob.
writer[first-name = "Bob"] All <writer> elements that have at least one <first-name> child with the value Bob.
writer[* = "Bob"] all writer elements containing any child element whose value is Bob.
writer[lastName = "Bob" and first-name = "Joe"] All <writer> elements that has a <lastName> child element with the value Bob and a <first-name> child element with the value Joe.
price[@intl = "Canada"] All <price> elements in the context node which have an intl attribute equal to "Canada".
degree[position() &lt; 3] The first two <degree> elements that are children of the context node.
p/text()[2] The second text node in each <p> element in the context node.
ancestor::book[1] The nearest <book> ancestor of the context node.
ancestor::book[writer][1] The nearest <book> ancestor of the context node and this <book> element has an <writer> element as its child.
ancestor::writer[parent::book][1] The nearest <writer> ancestor in the current context and this <writer> element is a child of a <book> element.

Web Technology Important Links - Create SiteMap - Monitor Website - SEO Health - All Google API - Blogspot Assistance links

Following are Important Links which are used in Web Technology Fields.

http://www.xml-sitemaps.com/
Get all the Public URL of webpage. You can download/view the URL's in form of CSV, XML, TXT and HTML.

http://www.labnol.org/internet/google-web-scraping/28450/
Scrap the content of public web-pages in csv in one click.

http://newrelic.com/server-monitoring
Monitor your server Error including ajax error. Get Notification by email of error. You can monitor the performance of your website.

http://seositecheckup.com/
Check SEO Health of your website.

http://gtmetrix.com/
Test Website Speed and Performance Optimization.

http://sandbox.ternarylabs.com/porthole/
Access Iframe from another Iframe

http://loadimpact.com
Check web server load

http://www.timeanddate.com/date/duration.html
Calculate duration between two dates

http://www.timeanddate.com/worldclock/converter.html
Time Zone Converter – Time Difference Calculator

https://code.google.com/apis/ajax/playground/
The AJAX Code Playground is an educational tool to show code examples for various Google Javascript APIs

https://www.flickr.com/services/api/misc.urls.html
flickr images having different size

http://benalman.com/projects/jquery-postmessage-plugin/
Cross Domain Communication from JavaScript

http://randomuser.me/
Unlimited free user detail with photos

http://www.gingersoftware.com/grammarcheck

Check the Grammar of description

http://smallseotools.com/plagiarism-checker/

Check the Uniqueness of  Description

http://www.feedthebot.com/tools/alt/
Check Alt Tag missing for images in website.


https://dev.twitter.com/rest/reference/get/users/show
Twitter API

http://www.browserstack.com/ 
Test your website for cross browser compatibility on real browsers. Instant access to multiple desktop and mobile browsers.

https://www.branah.com/text-to-image

Easily create an image online from text or HTML. The text to image converter supports multiple languages. You can use your own background image and font.

http://blog.slashpoundbang.com/post/12975232033/google-news-search-parameters-the-missing-manual
Google News API Parameter


For Blogger.com Only

http://www.theblogwidgets.com/2009/08/change-title-tags-in-blogger-for-more.html
Change the Title of every post of blog


http://www.helpfulbloggertips.com/2013/03/blogger-create-custom-error-404-page.html
Custom Redirect Page


http://blogtimenow.com/blogging/create-add-custom-robots-txt-file-blogger-crawl-index/
Update Robots.txt file of blog


http://helplogger.blogspot.in/2012/03/how-to-add-related-posts-widget-to.html
Add Related Post


http://techmarshal.blogspot.in/2013/02/simple-blogger-related-post-widget-without-thumbnail-text-only.html
Add Related Post - Without thumbnail


http://www.blogs911.com/2013/08/limiting-number-of-posts-in-labels-page.html
Limit the Number of post in Blogger Label

How to Add Numbered Page Navigation Widget for Blogger

http://helplogger.blogspot.in/2014/04/how-to-add-numbered-page-navigation-widget-for-blogger.html