bab v - xpath

15
XPATH

Upload: dion-prayoga

Post on 10-Apr-2015

293 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: BAB V - XPath

XPATH

Page 2: BAB V - XPath

Xpath adalah bahasa untuk menemukan informasi di dalam sebuah dokumen XML

Page 3: BAB V - XPath

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

Page 4: BAB V - XPath

Nodes

Element Attribute Text Namespace processing-instruction Comment document nodes

Page 5: BAB V - XPath

XML documents di anggap sebagai tree nodes (pohon node). element paling puncak dari pohon tersebut di sebut root element.

Page 6: BAB V - XPath

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

Page 7: BAB V - XPath

Contoh Lagi

atomic values "en” Harry Potter 2005

Page 8: BAB V - XPath

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.

Page 9: BAB V - XPath

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>

Page 10: BAB V - XPath

Expression

Ekspresi untuk memilih node

Perhatikan contoh!

Page 11: BAB V - XPath

Expression - Predicate

Selalu baca element paling kanan!

Page 12: BAB V - XPath

Expression-con’t

Unknown Nodes

Contoh

Page 13: BAB V - XPath

Expression Con’t

Memilih beberapa node sekaligus

Page 14: BAB V - XPath

Operator

Page 15: BAB V - XPath

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>