ใครเป็นผู้รับ/ส่ง XML ?
ผู้ส่ง
Web Sevices เช่น เว็บไซต์แสดงข้อมูลด้านสาธารณภัย (link)
ผู้รับ
Developer ที่ไปดึงข้อมูลจาก Web Service ได้ข้อมูลมาในรูปแบบ XML และนำข้อมูลไป process ต่อ
ผู้ใช้ทั่วไปที่ต้องการข้อมูล
XML Parser คืออะไร
XML Parser เป็นตัวแปลงจาก string เป็น DOM Object เพื่อใช้ในการจัดการข้อมูลได้
ตัวอย่างใน Javascript
text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
parser = new DOMParser();
xmlDoc = parser.parseFromString(text,"text/xml");
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
code
จากโค้ดด้านบนจะเห็นว่ามีการนำ XML แปลงไปเป็น DOM Object แล้วสามารถเรียกใช้ผ่านคำสั่ง getElementByTagname
ไม่มีความคิดเห็น:
แสดงความคิดเห็น