Download - BAB V - XPath
XPATH
Xpath adalah bahasa untuk menemukan informasi di dalam sebuah dokumen XML
XPath
XPath merupakan sintaks untuk mendefinisikan bagian2 XML document
XPath menggunakan path expressions untuk navigasi dalam XML documents
XPath terdiri atas fungsi2 standard XPath adalah element utama dalam
XSLT
Nodes
Element Attribute Text Namespace processing-instruction Comment document nodes
XML documents di anggap sebagai tree nodes (pohon node). element paling puncak dari pohon tersebut di sebut root element.
Contoh
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore> <book> <title lang="en"> </title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book></bookstore>
<bookstore> root node <author> element node lang=“en“$ attribute node <? … ?> Processing Instruction Node
Contoh Lagi
atomic values "en” Harry Potter 2005
Relationship
<bookstore> <book> <title lang="en">Harry Potter</title> <author>J K. Rowling</author> <year>2005</year> <price>29.99</price> </book></bookstore>
Parent Bookstore adalah parent dari book, dan book adalah parent dari title, author, year
Children kebalikan, author adalah children dari book, dan book adalah children dari bookstore
Sibling saudaraan, artinya cari yang mempnyai level sejajar, maka mereka adalah sibling, misal title, author, year, dan price adalah semuanya sibling
Ancestor pokoknya yang ada di atas sebuah element itu ancestor Decendant kebalikan dari ancestor, semua yang ada di bawah element
adalah decendant.
Dokumen XML Referensi
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
<book> <title lang="eng">Harry Potter</title> <price>29.99</price></book>
<book> <title lang="eng">Learning XML</title> <price>39.95</price></book>
</bookstore>
Expression
Ekspresi untuk memilih node
Perhatikan contoh!
Expression - Predicate
Selalu baca element paling kanan!
Expression-con’t
Unknown Nodes
Contoh
Expression Con’t
Memilih beberapa node sekaligus
Operator
Penggunaan di Browser
<script type="text/javascript">
function loadXMLDoc(dname){ if (window.XMLHttpRequest) { xhttp=new XMLHttpRequest(); } else { xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",dname,false); xhttp.send(""); return xhttp.responseXML;}
</script>