XPath Visualizer
Xpath Visualizer
For this example, we'll be using HttpBin API - This is an API that returns random xml and is perfect for demonstrating the power of Xpath. Additionally, you can filter html with Xpath, and change the endpoint to /html to return and filter it.
Once the request has been made and the response body has been returned, switch to the Visualize tab to start using the tool.
You will be presented with an Input Field to start adding your XPath expressions to start filtering the data. The queries will be evaluated in realtime and the filtered data will be presented once a valid query has been made.
As its evaluated in realtime, there will be parsing errors, these are expected and will be logged to the Visualizer console as info messages. If you also wanted see these as you enter your queries, there is a checkbox available that will display them above the filtered data.
Filtering the response data
Here are a few basic XPath queries that can be used against the HttpBin API:
//slide/title//slide/item//slide[*]/title
The queries above are quite simple but XPath gives you the ability to use a number of conditional methods, in the queries, to display the data in a number of different ways.
| XPath Expression | What's it doing |
|---|---|
//slide/title[text()=Overview] | Gets all the Overview entries in the for the title tag |
//slide[@type=all][1] | Gets any slide tags that have type attribute equal to all |
//em[contains(text(),Wonder)] | Gets all the em tags that contain the text Wonder |
Further xpath instructions
A list of the commands and expressions that can be used are listed here.
HEADERS
| Key | Datatype | Required | Description |
|---|---|---|---|
Content-Type | string |
RESPONSES
status: OK
{"results":[{"gender":"male","name":{"title":"Mr","first":"Mehmet","last":"Erginsoy"},"location":{"street":{"number":8914,"name":"Şehitler Cd"},"city":"Eskişehir","state":"Uşak","country":"Turkey","postcode":74105,"coordinates":{"latitude":"76.9881","longitude":"-13.4206"},"timezone":{"offset":"+4:00","description":"Abu Dhabi, Muscat, Baku, Tbilisi"}},"email":"mehmet.erginsoy@example.com","login":{"uuid":"a5ae55cb-172e-49b2-a4e3-4dd97eaad533","username":"whiteduck372","password":"dipper","salt":"fBi6KUkA","md5":"52f92b903b557d995fd038a857b6942f","sha1":"8160e2d3ce665f149877df72383daeb63812cf15","sha256":"44a317325212486ba705130161429717690cd2dd774357fb195d3a6f8ea256d9"},"dob":{"date":"1990-03-29T20:59:17.361Z","age":29},"registered":{"date":"2016-08-30T08:40:14.406Z","age":3},"phone":"(496)-683-2212","cell":"(405)-189-9732","id":{"name":"","value":null},"picture":{"large":"https://randomuser.me/api/portraits/men/59.jpg","medium":"https://randomuser.me/api/portraits/med/men/59.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/59.jpg"},"nat":"TR"},{"gender":"female","name":{"title":"Mrs","first":"Leanne","last":"Kowalski"},"location":{"street":{"number":1262,"name":"Lake of Bays Road"},"city":"Minto","state":"Nunavut","country":"Canada","postcode":"G8B 2T2","coordinates":{"latitude":"-67.3676","longitude":"-76.6779"},"timezone":{"offset":"-10:00","description":"Hawaii"}},"email":"leanne.kowalski@example.com","login":{"uuid":"6082defb-4429-4a77-9299-980537a10e06","username":"greenswan106","password":"383838","salt":"cwmCMgb5","md5":"bd20b076573fd7bab1d810c91103b19c","sha1":"7adf2c87e8f916c5f97a22a7c6e3f6351385f340","sha256":"293a652f42f6c3cd6ad8ef4eee748b37455f85b5d4374d4bbd0ee16efdc81210"},"dob":{"date":"1985-11-12T07:42:47.771Z","age":34},"registered":{"date":"2012-07-29T09:39:49.701Z","age":7},"phone":"327-775-3620","cell":"631-548-4287","id":{"name":"","value":null},"picture":{"large":"https://randomuser.me/api/portraits/women/0.jpg","medium":"https://randomuser.me/api/portraits/med/women/0.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/women/0.jpg"},"nat":"CA"},{"gender":"female","name":{"title":"Mrs","first":"Olivia","last":"Larsen"},"location":{"street":{"number":970,"name":"Klitvej"},"city":"Vipperød","state":"Hovedstaden","country":"Denmark","postcode":51991,"coordinates":{"latitude":"66.7954","longitude":"-177.5499"},"timezone":{"offset":"+4:00","description":"Abu Dhabi, Muscat, Baku, Tbilisi"}},"email":"olivia.larsen@example.com","login":{"uuid":"c9054ccb-8593-4195-a87c-74db3e03c34f","username":"happycat286","password":"leader","salt":"2VpzjoNa","md5":"4361b4063f208341d177806cb27c1e6a","sha1":"8061da379ec482a4cfe429ef0c8c7b2eca8257c6","sha256":"71f9d0d9605a55cf3b7f0f0118381127c8aaef0269d3d5cf72bc12dd7bcc8d62"},"dob":{"date":"1986-05-04T11:11:50.694Z","age":33},"registered":{"date":"2016-07-14T23:21:23.968Z","age":3},"phone":"90487065","cell":"16314531","id":{"name":"CPR","value":"040586-8449"},"picture":{"large":"https://randomuser.me/api/portraits/women/78.jpg","medium":"https://randomuser.me/api/portraits/med/women/78.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/women/78.jpg"},"nat":"DK"},{"gender":"male","name":{"title":"Mr","first":"Aleksi","last":"Kauppila"},"location":{"street":{"number":716,"name":"Tehtaankatu"},"city":"Orivesi","state":"Finland Proper","country":"Finland","postcode":85410,"coordinates":{"latitude":"47.7446","longitude":"-18.2149"},"timezone":{"offset":"+8:00","description":"Beijing, Perth, Singapore, Hong Kong"}},"email":"aleksi.kauppila@example.com","login":{"uuid":"9a16f47d-c462-43a0-8623-cdde17dc1a81","username":"blackleopard647","password":"eatme","salt":"7ki1RSIN","md5":"79a0effb4405c33627a8078c43ef0415","sha1":"9eba1d83d8f9b46afb650c657dd5bbad442fb281","sha256":"1bc5f6881a474ee98f693d25bf0c87a017f54c0821bdbd1bd9f1cdf1741547eb"},"dob":{"date":"1983-07-31T23:46:45.064Z","age":36},"registered":{"date":"2002-08-21T16:21:06.190Z","age":17},"phone":"07-501-036","cell":"041-773-81-41","id":{"name":"HETU","value":"NaNNA727undefined"},"picture":{"large":"https://randomuser.me/api/portraits/men/8.jpg","medium":"https://randomuser.me/api/portraits/med/men/8.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/8.jpg"},"nat":"FI"},{"gender":"male","name":{"title":"Mr","first":"Lorenzo","last":"Guerrero"},"location":{"street":{"number":4553,"name":"Calle de Arganzuela"},"city":"Albacete","state":"Andalucía","country":"Spain","postcode":66370,"coordinates":{"latitude":"26.8788","longitude":"-66.5230"},"timezone":{"offset":"-9:00","description":"Alaska"}},"email":"lorenzo.guerrero@example.com","login":{"uuid":"26862c77-f721-44d1-a92d-f22dbb8a5289","username":"brownswan804","password":"chainsaw","salt":"4n87kLJO","md5":"255707721809a71f32094f4dab97bac2","sha1":"8cb6df48ab5d385061ff0c4ef6c5e4edddc555f7","sha256":"8f0a3d2ac7b84d2a76e7ea2c78e4d164bccd35673072f7c66d5f29d7c4594549"},"dob":{"date":"1978-01-02T23:45:26.051Z","age":41},"registered":{"date":"2008-06-15T15:31:44.324Z","age":11},"phone":"963-466-282","cell":"677-527-657","id":{"name":"DNI","value":"34983056-J"},"picture":{"large":"https://randomuser.me/api/portraits/men/75.jpg","medium":"https://randomuser.me/api/portraits/med/men/75.jpg","thumbnail":"https://randomuser.me/api/portraits/thumb/men/75.jpg"},"nat":"ES"}],"info":{"seed":"8f43f8dbe4a52951","results":5,"page":1,"version":"1.3"}}