XPath

From BC$ MobileTV Wiki
Jump to: navigation, search
Venn Diagram - XML Manipulation Techologies

XML Path language (commonly abbreviated XPath) is a technology for accessing XML elements, attributes and their associated data. XPath, XQuery, XLink, XPoint, XSLT form a family of W3C recommended platform-agnostic data manipulation technologies.


Specifications



EXAMPLES

Sample XML

Given the following XML:

<recommendations>
   <recommendation category="random">
     <title author="http://bcmoney-mobiletv.com/titounetsan">La Chance</title>
     <image>http://bcmoney-mobiletv.com/thumb/1_1049.jpg</image>
     <link>http://bcmoney-mobiletv.com/view/1049/la-chance/</link>
   <recommendation>
   <recommendation category="friends">
     <title author="http://bcmoney-mobiletv.com/rballs">Free Aggressive High Fives</title>
     <image>http://bcmoney-mobiletv.com/thumb/1_508.jpg</image>
     <link>http://bcmoney-mobiletv.com/view/508/free-agressive-high-fives/</link>
   <recommendation>
   <recommendation category="friends">
     <title author="http://bcmoney-mobiletv.com/rballs">Jin - I Got A Love</title>
     <image>http://bcmoney-mobiletv.com/thumb/1_239.jpg</image>
     <link>http://bcmoney-mobiletv.com/view/239/jin-i-got-a-love/</link>
   <recommendation>
   <recommendation category="viewing history">
     <title author="http://bcmoney-mobiletv.com/bryan">George Carlin on Global Warming</title>
     <image>http://bcmoney-mobiletv.com/thumb/1_348.jpg</image>
     <link>http://bcmoney-mobiletv.com/view/348/george-carlin-on-global-warming/</link>
   <recommendation>
   <recommendation category="favorites">
     <title author="http://bcmoney-mobiletv.com/thesns">Jim Carey - Karate Sensei</title>
     <image>http://bcmoney-mobiletv.com/thumb/1_946.jpg</image>
     <link>http://bcmoney-mobiletv.com/view/946/jim-carey-karate-sensei/</link>
   <recommendation>
</recommendations>

We could extract information as follows:

TITLE(s)

//recommendations/recommendation/title

gives:

  1. La Chance
  2. Free Aggressive High Fives
  3. Jin - I Got A Love
  4. George Carlin on Global Warming
  5. Jim Carey - Karate Sensei


third TITLE

//recommendations/recommendation[3]/title

gives:

Jin - I Got A Love


TITLE(s) by author named 'bryan'

//recommendations/recommendation/title[@author='bryan']

gives:

George Carlin on Global Warming


TITLE(s) for RECOMMENDATION(s) via 'favorites' category

A "category" of recommendation type could be specified (i.e. could be from friends, purchase history, viewing history, random/surprise, "related" to current video, generated based on a categorization of your "favorites", etc...)

//recommendations/recommendation[@category='favorites']/title

gives:

Jim Carey - Karate Sensei


IMAGE(s)

//recommendations/recommendation/image

gives:

  1. http://bcmoney-mobiletv.com/thumb/1_1049.jpg
  2. http://bcmoney-mobiletv.com/thumb/1_508.jpg
  3. http://bcmoney-mobiletv.com/thumb/1_239.jpg
  4. http://bcmoney-mobiletv.com/thumb/1_348.jpg
  5. http://bcmoney-mobiletv.com/thumb/1_946.jpg


LINK(s)

//recommendations/recommendation/link

gives:

  1. http://bcmoney-mobiletv.com/view/1049/la-chance/
  2. http://bcmoney-mobiletv.com/view/508/free-agressive-high-fives/
  3. http://bcmoney-mobiletv.com/view/239/jin-i-got-a-love/
  4. http://bcmoney-mobiletv.com/view/348/george-carlin-on-global-warming/
  5. http://bcmoney-mobiletv.com/view/946/jim-carey-karate-sensei/


AUTHOR(s) (attribute)

//recommendations/recommendation/title/@author

gives:

  1. http://bcmoney-mobiletv.com/titounetsan
  2. http://bcmoney-mobiletv.com/rballs
  3. http://bcmoney-mobiletv.com/rballs
  4. http://bcmoney-mobiletv.com/bryan
  5. http://bcmoney-mobiletv.com/thesns


AUTHOR(s) with URL removed

Any element or attribute can be shown with characters matching the remove string, removed (in this case in order to give "author" names only)

//recommendations/recommendation/title/@author   ==> string replace 
JS==> .replace('http://bcmoney-mobiletv.com/ ',' '));    ~~OR~~   PHP==> str_replace(item,'http://bcmoney-mobiletv.com/ ',' ') 

gives:

  1. titounetsan
  2. rballs
  3. rballs
  4. bryan
  5. thesns



Tools


Resources


Tutorials

[1] [2] [3]


External Links


See Also

XML | XQuery | XSLT
  1. Microsoft "Power Automate" community -- xPath & SOAP message: https://powerusers.microsoft.com/t5/General-Power-Automate/help-with-Xpath-and-Soap-message/td-p/322341#
  2. Get value from SOAP Message using XPath: https://stackoverflow.com/questions/5390723/get-value-from-soap-message-using-xpath
  3. How to use XPath with namespaces in RIT: https://www.ibm.com/support/pages/how-use-xpath-namespaces-rit