You Now Here »

Tutorial PHP Cara mudah parsing data untuk mengambil value file XML  (Read 2184 times - 134 votes) 

DANNY

G-Plus Author
  • ADMINISTRATOR
  • More Share Forum Topic
  • [MS] kepala suku
  • *
  • DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!DANNY sangat terkenal!
  • Rep Power: 6
  • Join: September 30, 2009
  • Posts: 11,931
  • Poin: 193.394
    • WWW
  • IP member tracker Logged


  :ehm
biasanya kita menggunakan fungsi PHP regular expression ataupun fungsi explode untuk memecah dan mengambil data berdasarkan keyword tertentu, namun dalam hal ini pada PHP versi 5 sudah terdapat fungsi modul untuk mendeklarasikan file XML dalam pengolahan data, oke langsung saja:

Syntax
Code: [Select]
class SimpleXMLElement
{
string children(ns,is_prefix)
}

XML File
Code: [Select]
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>

PHP Code
Code: [Select]
<?php
$xml 
simplexml_load_file("test.xml");

foreach (
$xml->children() as $child)
  {
  echo 
"Child node: " $child "<br />";
  }
?>

RESULT
Quote
Child node: Tove
Child node: Jani
Child node: Reminder
Child node: Don't forget me this weekend!

  :beer:
moga bermanfaat


View Mobile Web Short URL: