XML. 6.6 XPath. XPath is a syntax used for selecting parts of an XML document

Podobne dokumenty
Weronika Mysliwiec, klasa 8W, rok szkolny 2018/2019

Helena Boguta, klasa 8W, rok szkolny 2018/2019

Zakopane, plan miasta: Skala ok. 1: = City map (Polish Edition)

XML Path Language (XPath)

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Tychy, plan miasta: Skala 1: (Polish Edition)

Rozpoznawanie twarzy metodą PCA Michał Bereta 1. Testowanie statystycznej istotności różnic między jakością klasyfikatorów

Karpacz, plan miasta 1:10 000: Panorama Karkonoszy, mapa szlakow turystycznych (Polish Edition)

Stargard Szczecinski i okolice (Polish Edition)

ARNOLD. EDUKACJA KULTURYSTY (POLSKA WERSJA JEZYKOWA) BY DOUGLAS KENT HALL

XPath XML Path Language. XPath. XSLT część 1. XPath data model. Wyrażenia XPath. Osie (axes) Location paths

XPath XML Path Language. XPath. XSLT część 1. XPath data model. Wyrażenia XPath. Location paths. Osie (axes)

ANKIETA ŚWIAT BAJEK MOJEGO DZIECKA

OpenPoland.net API Documentation

Języki XPath i XQuery

Dolny Slask 1: , mapa turystycznosamochodowa: Plan Wroclawia (Polish Edition)

Katowice, plan miasta: Skala 1: = City map = Stadtplan (Polish Edition)

TTIC 31210: Advanced Natural Language Processing. Kevin Gimpel Spring Lecture 9: Inference in Structured Prediction

Testy jednostkowe - zastosowanie oprogramowania JUNIT 4.0 Zofia Kruczkiewicz

Wybrzeze Baltyku, mapa turystyczna 1: (Polish Edition)

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Rev Źródło:

Słowem wstępu. Standard: W3C XPath razem XSLT 1.0. XPath razem z XQuery 1.0 i XSLT 2.0. XPath trwają prace nad XPath 3.

SSW1.1, HFW Fry #20, Zeno #25 Benchmark: Qtr.1. Fry #65, Zeno #67. like

Wprowadzenie do programu RapidMiner, część 2 Michał Bereta 1. Wykorzystanie wykresu ROC do porównania modeli klasyfikatorów

Emilka szuka swojej gwiazdy / Emily Climbs (Emily, #2)

Steeple #3: Gödel s Silver Blaze Theorem. Selmer Bringsjord Are Humans Rational? Dec RPI Troy NY USA

MaPlan Sp. z O.O. Click here if your download doesn"t start automatically

Blow-Up: Photographs in the Time of Tumult; Black and White Photography Festival Zakopane Warszawa 2002 / Powiekszenie: Fotografie w czasach zgielku

Języki XPath i XQuery

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Surname. Other Names. For Examiner s Use Centre Number. Candidate Number. Candidate Signature

Miedzy legenda a historia: Szlakiem piastowskim z Poznania do Gniezna (Biblioteka Kroniki Wielkopolski) (Polish Edition)

USB firmware changing guide. Zmiana oprogramowania za przy użyciu połączenia USB. Changelog / Lista Zmian

HAPPY ANIMALS L01 HAPPY ANIMALS L03 HAPPY ANIMALS L05 HAPPY ANIMALS L07

HAPPY ANIMALS L02 HAPPY ANIMALS L04 HAPPY ANIMALS L06 HAPPY ANIMALS L08

Wykład 5_2 Arkusze stylów dziedziczenie. Technologie internetowe Zofia Kruczkiewicz

EXAMPLES OF CABRI GEOMETRE II APPLICATION IN GEOMETRIC SCIENTIFIC RESEARCH

Arrays -II. Arrays. Outline ECE Cal Poly Pomona Electrical & Computer Engineering. Introduction

Machine Learning for Data Science (CS4786) Lecture11. Random Projections & Canonical Correlation Analysis

Miedzy legenda a historia: Szlakiem piastowskim z Poznania do Gniezna (Biblioteka Kroniki Wielkopolski) (Polish Edition)

Instrukcja obsługi User s manual

Zmiany techniczne wprowadzone w wersji Comarch ERP Altum

Machine Learning for Data Science (CS4786) Lecture 11. Spectral Embedding + Clustering

Języki XPath i XQuery

Karpacz, plan miasta 1:10 000: Panorama Karkonoszy, mapa szlakow turystycznych (Polish Edition)

Previously on CSCI 4622

Zestawienie czasów angielskich

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

LEARNING AGREEMENT FOR STUDIES

Raport bieżący: 44/2018 Data: g. 21:03 Skrócona nazwa emitenta: SERINUS ENERGY plc

17-18 września 2016 Spółka Limited w UK. Jako Wehikuł Inwestycyjny. Marek Niedźwiedź. InvestCamp 2016 PL

Zarządzanie sieciami telekomunikacyjnymi

Dolny Slask 1: , mapa turystycznosamochodowa: Plan Wroclawia (Polish Edition)

deep learning for NLP (5 lectures)

Camspot 4.4 Camspot 4.5

XPath i XQuery. Patryk Czarnik. XML i nowoczesne technologie zarządzania treścią 2011/12. Wprowadzenie Status Model danych XPath

SubVersion. Piotr Mikulski. SubVersion. P. Mikulski. Co to jest subversion? Zalety SubVersion. Wady SubVersion. Inne różnice SubVersion i CVS

OSTC GLOBAL TRADING CHALLENGE MANUAL

Change Notice/ Zmienić zawiadomienie BLS Instructor Manual / Podstawowe czynności resuscytacyjne Podrecznik Instruktora

TTIC 31210: Advanced Natural Language Processing. Kevin Gimpel Spring Lecture 8: Structured PredicCon 2

Karpacz, plan miasta 1:10 000: Panorama Karkonoszy, mapa szlakow turystycznych (Polish Edition)

Wroclaw, plan nowy: Nowe ulice, 1:22500, sygnalizacja swietlna, wysokosc wiaduktow : Debica = City plan (Polish Edition)

Revenue Maximization. Sept. 25, 2018

General Certificate of Education Ordinary Level ADDITIONAL MATHEMATICS 4037/12

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Machine Learning for Data Science (CS4786) Lecture 24. Differential Privacy and Re-useable Holdout

PLSH1 (JUN14PLSH101) General Certificate of Education Advanced Subsidiary Examination June Reading and Writing TOTAL

Zdecyduj: Czy to jest rzeczywiście prześladowanie? Czasem coś WYDAJE SIĘ złośliwe, ale wcale takie nie jest.


Kurs WWW Język XML, część II

Polska Szkoła Weekendowa, Arklow, Co. Wicklow KWESTIONRIUSZ OSOBOWY DZIECKA CHILD RECORD FORM

Instrukcja konfiguracji usługi Wirtualnej Sieci Prywatnej w systemie Mac OSX

Pielgrzymka do Ojczyzny: Przemowienia i homilie Ojca Swietego Jana Pawla II (Jan Pawel II-- pierwszy Polak na Stolicy Piotrowej) (Polish Edition)

How to share data from SQL database table to the OPC Server? Jak udostępnić dane z tabeli bazy SQL do serwera OPC? samouczek ANT.

Polski Krok Po Kroku: Tablice Gramatyczne (Polish Edition) By Anna Stelmach

Domy inaczej pomyślane A different type of housing CEZARY SANKOWSKI

Oxford PWN Polish English Dictionary (Wielki Slownik Polsko-angielski)

Extraclass. Football Men. Season 2009/10 - Autumn round

POLITYKA PRYWATNOŚCI / PRIVACY POLICY


DO MONTAŻU POTRZEBNE SĄ DWIE OSOBY! INSTALLATION REQUIRES TWO PEOPLE!

Egzamin maturalny z języka angielskiego na poziomie dwujęzycznym Rozmowa wstępna (wyłącznie dla egzaminującego)

Gradient Coding using the Stochastic Block Model

Angielski bezpłatne ćwiczenia - gramatyka i słownictwo. Ćwiczenie 7

MS Visual Studio 2005 Team Suite - Performance Tool

Proposal of thesis topic for mgr in. (MSE) programme in Telecommunications and Computer Science


TYLKO DO UŻYTKU WŁASNEGO! PERSONAL USE ONLY!

User s manual for icarwash

Leba, Rowy, Ustka, Slowinski Park Narodowy, plany miast, mapa turystyczna =: Tourist map = Touristenkarte (Polish Edition)

Patients price acceptance SELECTED FINDINGS

SNP SNP Business Partner Data Checker. Prezentacja produktu

y = The Chain Rule Show all work. No calculator unless otherwise stated. If asked to Explain your answer, write in complete sentences.

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

ERASMUS + : Trail of extinct and active volcanoes, earthquakes through Europe. SURVEY TO STUDENTS.

January 1st, Canvas Prints including Stretching. What We Use

Realizacja systemów wbudowanych (embeded systems) w strukturach PSoC (Programmable System on Chip)

Installation of EuroCert software for qualified electronic signature

Poland) Wydawnictwo "Gea" (Warsaw. Click here if your download doesn"t start automatically

Transkrypt:

6 XML 6.6 XPath What is XPath? XPath is a syntax used for selecting parts of an XML document The way XPath describes paths to elements is similar to the way an operating system describes paths to files XPath is almost a small programming language; it has functions, tests, and expressions XPath is a W3C standard http://www.w3.org/tr/xpath XPath is not itself written as XML, but is used heavily in XSLT 1

Terminology <library> <book> <chapter> </chapter> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> </book> </library> library is the parent of book; book is the parent of the two chapters The two chapters are the children of book, and the section is the child of the second chapter The two chapters of the book are siblings (they have the same parent) library, book, and the second chapter are the ancestors of the section The two chapters, the section, and the two paragraphs are the descendents of the book 2

Paths Operating system: XPath: / = the root directory /library = the root element (if named library ) /users/dave/foo = the file named foo in dave in users foo = the file named foo in the current directory /library/book/chapter/section = every section element in a chapter in every book in the library section = every section element that is a child of the current element. = the current directory. = the current element.. = the parent directory.. = parent of the current element /users/dave/* = all the files in /users/dave /library/book/chapter/* = all the elements in /library/book/chapter Slashes A path that begins with a / represents an absolute path, starting from the top of the document Example: /email/message/header/from Note that even an absolute path can select more than one element A slash by itself means the whole document A path that does not begin with a / represents a path starting from the current element Example: header/from A path that begins with // can start from anywhere in the document Example: //header/from selects every element from that is a child of an element header This can be expensive, since it involves searching the entire document 3

Brackets and last() A number in brackets selects a particular matching child Example: /library/book[1] selects the first book of the library Example: //chapter/section[2] selects the second section of every chapter in the XML document Example: //book/chapter[1]/section[2] Only matching elements are counted; for example, if a book has both sections and exercises, the latter are ignored when counting sections The function last() in brackets selects the last matching child Example: /library/book/chapter[last()] You can even do simple arithmetic Example: /library/book/chapter[last()-1] Stars A star, or asterisk, is a wild card --it means all the elements at this level Example: /library/book/chapter/* selects every child of every chapter of every book in the library Example: //book/* selects every child of every book (chapters, tableofcontents, index, etc.) Example: /*/*/*/paragraph selects every paragraph that has exactly three ancestors Example: //* selects every element in the entire document 4

Attributes I You can select attributes by themselves, or elements that have certain attributes Remember: an attribute consists of a name-value pair, for example in <chapter num="5">, the attribute is named num To choose the attribute itself, prefix the name with @ Example: @num will choose every attribute named num Example: //@* will choose every attribute, everywhere in the document To choose elements that have a given attribute, put the attribute name in square brackets Example: //chapter[@num] will select every chapter element (anywhere in the document) that has an attribute named num Attributes II //chapter[@num] selects every chapter element with an attribute num //chapter[not(@num)] selects every chapter element that does not have a num attribute //chapter[@*] selects every chapter element that has any attribute //chapter[not(@*)] selects every chapter element with no attributes 5

Values of attributes //chapter[@num='3'] selects every chapter element with an attribute num with value 3 The normalize-space() function can be used to remove leading and trailing spaces from a value before comparison Example: //chapter[normalize-space(@num)="3"] Axes An axis (plural axes) is a set of nodes relative to a given node; X::Y means choose Y from the X axis self:: is the set of current nodes (not too useful) self::node() is the current node child:: is the default, so /child::x is the same as /X parent:: is the parent of the current node ancestor:: is all ancestors of the current node, up to and including the root descendant:: is all descendants of the current node (Note: never contains attribute or namespace nodes) preceding:: is everything before the current node in the entire XML document following:: is everything after the current node in the entire XML document 6

Axes (outline view) Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes (if we ignore attribute and namespace nodes) <library> <book> <chapter/> <chapter> <section> <paragraph/> <paragraph/> </section> </chapter> <chapter/> </book> <book/> </library> //chapter[2]/self::* //chapter[2]/preceding::* //chapter[2]/following::* //chapter[2]/ancestor::* //chapter[2]/descendant::* Axes (tree view) Starting from a given node, the self, preceding, following, ancestor, and descendant axes form a partition of all the nodes (if we ignore attribute and namespace nodes) ancestor book[1] library following book[2] preceding chapter[1] self chapter[2] chapter[3] section[1] descendant paragraph[1] paragraph[2] 7

Axis Examples //book/descendant::* is all descendants of every book //book/descendant::section is all section descendants of every book //parent::* is every element that is a parent, i.e., is not a leaf //section/parent::* is every parent of a section element //parent::chapter is every chapter that is a parent, i.e., has children /library/book[3]/following::* is everything after the third book in the library More axes ancestor-or-self:: ancestors plus the current node descendant-or-self:: descendants plus the current node attribute:: is all attributes of the current node namespace:: is all namespace nodes of the current node preceding:: is everything before the current node in the entire XML document following-sibling:: is all siblings after the current node Note: preceding-sibling:: and following-sibling:: do not apply to attribute nodes or namespace nodes 8

Abbreviations for axes (none) is the same as child:: @ is the same as attribute::. is the same as self::node().//x is the same as self::node()/descendant-or-self::node()/child::x.. is the same as parent::node()../x is the same as parent::node()/child::x // is the same as /descendant-or-self::node()/ //X is the same as /descendant-or-self::node()/child::x Arithmetic Expressions + - * div mod add subtract multiply (not /) divide modulo (remainder) 9

Equality Tests = equals (Notice it s not ==)!= not equals But it s not that simple! value = node-set will be true if the node-set contains any node with a value that matches value value!= node-set will be true if the node-set contains any node with a value that does not match value Hence, value = node-set and value!= node-set may both be true at the same time! Other Boolean Operators and (infix operator) or (infix operator) Example: count = 0 or count = 1 not() (function) The following are used for numerical comparisons only: < less than <= less than or equal to > greater than >= greater than or equal to 10

Some XPath Functions XPath contains a number of functions on node sets, numbers, and strings; here are a few of them: count(elem) counts the number of selected elements Example: //chapter[count(section)=1] selects chapters with exactly two section children name() returns the name of the element Example: //*[name()='section'] is the same as //section starts-with(arg1, arg2) tests if arg1 starts with arg2 Example: //*[starts-with(name(), 'sec'] contains(arg1, arg2) tests if arg1 contains arg2 Example: //*[contains(name(), 'ect'] References W3School XPath Tutorial http://www.w3schools.com/xpath/default.asp MSXML 4.0 SDK Several online presentations 11

Reading List W3School XPath Tutorial http://www.w3schools.com/xpath/default.asp 12