SlideShare a Scribd company logo
1 of 12
Lập trình mạng – Chương 7 1
ỨNG DỤNG XML
TRONG LẬP TRÌNH MẠNG
1.1 Giới thiệu ngôn ngữ XML
1.2 XML trong các ứng dụng mạng
1.3 Một số ví dụ.
Lập trình mạng – Chương 7 2
1.1 Giới thiệu ngôn ngữ XML
• XML (Extensible Markup Language) là tập con của SGML (Standard
Generalized Markup Language), được đơn giản hóa để hướng tới
web.
• Các đặc điểm:
• Meaningful Searches
• XML/EDI (XML for Electronic Data Interchange)
• Enterprise Application Integration
• Data accessibility/ Application simplification
Lập trình mạng – Chương 7 3
1.1 Giới thiệu ngôn ngữ XML
• So sánh HTML và XML:
• Đều là tập con của SGML
• HTML định dạng các tag để hiển thị, XML định dạng các tag thể hiện ngữ
nghĩa dữ liệu.
• XML hướng đến việc xử lý dữ liệu ở client.
• XML có thể làm dữ liệu trao đổi giữa các ứng dụng trên Internet.
• XML có thể dùng để lưu trữ dữ liệu như một database.
Lập trình mạng – Chương 7 4
1.1 Giới thiệu ngôn ngữ XML
• Cấu trúc file XML:
• Được định nghĩa dựa vào các tags theo cấu trúc phân cấp.
• Các tag do người sử dụng đặt
• Tags và cấu trúc XML được định nghĩa theo DTD (Document Type Definition)
hoặc XML Schema
Lập trình mạng – Chương 7 5
1.1 Giới thiệu ngôn ngữ XML
• Ví dụ file XML đơn giản:
<?xml version="1.0"?>
<!DOCTYPE personals SYSTEM "personal.dtd">
<personals>
<person id="N.URAMOTO">
<name><family>URAMOTO</family> <given>Naohiko</given></name>
<email>uramoto@jp.ibm.com</email>
<link manager=" H.MARUYAMA"/>
</person>
<person id="K.TAMURA">
<name> <family>TAMURA</family> <given>Kent</given> </name>
<!-- This URL is mail address.-->
<url href="mailto:kent@trl.ibm.co.jp"/>
<url href="mailto:tkent@jp.ibm.com"/>
<link manager="H.MARUYAMA"/>
</person>
</personals>
Lập trình mạng – Chương 7 6
1.1 Giới thiệu ngôn ngữ XML
• DTD:
<?xml encoding="US-ASCII"?>
<!ELEMENT personals (person)+>
<!ELEMENT person (name,email*,url*,link?)>
<!ATTLIST person id ID #REQUIRED>
<!ELEMENT family (#PCDATA)>
<!ELEMENT given (#PCDATA)>
<!ELEMENT name (#PCDATA|family|given)*>
<!ELEMENT email (#PCDATA)>
<!ELEMENT url EMPTY>
<!ATTLIST url href CDATA #REQUIRED>
<!ELEMENT link EMPTY>
<!ATTLIST link
manager IDREF #IMPLIED
subordinates IDREFS #IMPLIED>
Lập trình mạng – Chương 7 7
1.1 Giới thiệu ngôn ngữ XML
• Truy xuất các phần tử trong file XML:
• Có thể sử dụng bất cứ ngôn ngữ lập trình trên các platform khác nhau.
• Các cách truy xuất đã được W3C(www.w3c.org) định nghĩa
• Document Object Model(DOM)
• XPointer
• XML StyleSheet Language(XSL)
• XML Query Language(XQL)
• …
Lập trình mạng – Chương 7 8
1.2 XML trong các ứng dụng mạng
• Định nghĩa các format dữ liệu để trao đổi:
• Cấu trúc file XML với DTD hay XML Schema quy định về protocol giao tiếp.
• Dữ liệu được biểu diễn theo các tag.
• Là môi trường để các hệ thống không đồng nhất có thể giao tiếp với nhau.
• Hệ thống cho phép mở rộng nhiều đối tượng tham gia, mở rộng giao dịch mà
không ảnh hưởng đến các giao dịch cũ.
• Có thể truyền qua giao thức HTTP
Lập trình mạng – Chương 7 9
1.2 XML trong các ứng dụng mạng
• Ví dụ mô hình giao dịch ngân hàng:
XML
Bank
C
Bank
B
Bank
A
Lập trình mạng – Chương 7 10
1.2 XML trong các ứng dụng mạng
• Các công nghệ dựa trên XML được sử dụng hiện nay:
• Simple Object Access Protocol(SOAP)
• Các dữ liệu XML được truyền qua giao thức HTTP như một đối tượng.
• Web services
• Chuẩn XML được hỗ trợ để truyền giữa các ứng dụng web để trao đổi dữ liệu.
• Microsoft .NET Framework
Lập trình mạng – Chương 7 11
1.3 Một số ví dụ
1. import org.apache.xerces.parsers.DOMParser;
2. import org.apache.xml.serialize.*;import org.w3c.dom.*;
3. import org.xml.sax.*;
4. private Document document;
5. private Node root;
6. private DOMParser parser = new DOMParser();
7. try
8. {
9. //pre-parse
10. ByteArrayInputStream input = new ByteArrayInputStream(inBuffer);
11. parser.setFeature("http://apache.org/xml/"+
12. "features/dom/include-ignorable-whitespace",false);
13. parser.parse(new InputSource(input));
14. document=parser.getDocument();
15. //Set DOCTYPE for input document
16. OutputFormat format=new OutputFormat();
17. format.setDoctype(null,"requestInformation.dtd");
Lập trình mạng – Chương 7 12
18. ByteArrayOutputStream output = new ByteArrayOutputStream();
19. XMLSerializer serial =new XMLSerializer(output,format);
20. serial.serialize(document);
21. inBuffer = output.toByteArray();
22. //real-parse
23. input = new ByteArrayInputStream(inBuffer);
24. parser.reset();
25. parser.parse(new InputSource(input));
26. document=parser.getDocument();
27. root = this.document.getDocumentElement();
28.
29. //Get information
30. Node cardNumberNode = root.getFirstChild();
31. cardNumber = cardNumberNode.getFirstChild().getNodeValue();
32. cardNumber = this.cardNumber.trim();
33. }catch (Exception e){}

More Related Content

Viewers also liked

Slide 1 - Thiết kế Web cơ bản
 Slide 1 - Thiết kế Web cơ bản Slide 1 - Thiết kế Web cơ bản
Slide 1 - Thiết kế Web cơ bảnSống Khác
 
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPT
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPTBài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPT
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPTMasterCode.vn
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSSAmit Tyagi
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet pptabhilashagupta
 
Fx 570 vn-plus_vi
Fx 570 vn-plus_viFx 570 vn-plus_vi
Fx 570 vn-plus_vimaytinh_5p
 

Viewers also liked (11)

Slide 00 gioi thieu
Slide 00   gioi thieuSlide 00   gioi thieu
Slide 00 gioi thieu
 
Tài liệu HTML5-CSS3
Tài liệu HTML5-CSS3Tài liệu HTML5-CSS3
Tài liệu HTML5-CSS3
 
Bài giảng HTML5-CSS3
Bài giảng HTML5-CSS3Bài giảng HTML5-CSS3
Bài giảng HTML5-CSS3
 
Slide 1 - Thiết kế Web cơ bản
 Slide 1 - Thiết kế Web cơ bản Slide 1 - Thiết kế Web cơ bản
Slide 1 - Thiết kế Web cơ bản
 
CSS Basics
CSS BasicsCSS Basics
CSS Basics
 
CSS for Beginners
CSS for BeginnersCSS for Beginners
CSS for Beginners
 
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPT
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPTBài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPT
Bài 1 XHTML: Cấu trúc nội dung web - Giáo trình FPT
 
Introduction to CSS
Introduction to CSSIntroduction to CSS
Introduction to CSS
 
cascading style sheet ppt
cascading style sheet pptcascading style sheet ppt
cascading style sheet ppt
 
Fx 570 vn-plus_vi
Fx 570 vn-plus_viFx 570 vn-plus_vi
Fx 570 vn-plus_vi
 
CSS ppt
CSS pptCSS ppt
CSS ppt
 

Similar to ứNg dụng xml

Bài thuyết trình môn công nghệ web
Bài thuyết trình môn công nghệ webBài thuyết trình môn công nghệ web
Bài thuyết trình môn công nghệ webTony Huynh
 
Slide Web Service
Slide Web ServiceSlide Web Service
Slide Web Serviceask bills
 
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNG
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNGMÔ HÌNH IOS TRONG HỆ THỐNG MẠNG
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNGPMC WEB
 
Kiến thức cần thiết làm việc
Kiến thức cần thiết làm việcKiến thức cần thiết làm việc
Kiến thức cần thiết làm việcmanhvokiem
 
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNG
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNGGIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNG
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNGPMC WEB
 
Ex 1 chapter03-appliation-layer-tony_chen - tieng viet
Ex 1 chapter03-appliation-layer-tony_chen - tieng vietEx 1 chapter03-appliation-layer-tony_chen - tieng viet
Ex 1 chapter03-appliation-layer-tony_chen - tieng vietĐô GiẢn
 
Tìm hiểu web service
Tìm hiểu web serviceTìm hiểu web service
Tìm hiểu web serviceThieu Mao
 
1 giới thiệu-cài đặt oracle
1 giới thiệu-cài đặt oracle1 giới thiệu-cài đặt oracle
1 giới thiệu-cài đặt oraclehoangdinhhanh88
 
Ldap introduce
Ldap introduceLdap introduce
Ldap introducelaonap166
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳ0909128965
 
LINQ TO XML
LINQ TO XMLLINQ TO XML
LINQ TO XMLbiendltb
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳNguyễn Vân
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳThu Hien
 

Similar to ứNg dụng xml (20)

Bài thuyết trình môn công nghệ web
Bài thuyết trình môn công nghệ webBài thuyết trình môn công nghệ web
Bài thuyết trình môn công nghệ web
 
Slide Web Service
Slide Web ServiceSlide Web Service
Slide Web Service
 
Sof301 slide1
Sof301   slide1Sof301   slide1
Sof301 slide1
 
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNG
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNGMÔ HÌNH IOS TRONG HỆ THỐNG MẠNG
MÔ HÌNH IOS TRONG HỆ THỐNG MẠNG
 
Kiến thức cần thiết làm việc
Kiến thức cần thiết làm việcKiến thức cần thiết làm việc
Kiến thức cần thiết làm việc
 
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNG
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNGGIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNG
GIỚI THIỆU VỀ MÔ HÌNH ỨNG DỤNG MẠNG
 
Ex 1 chapter03-appliation-layer-tony_chen - tieng viet
Ex 1 chapter03-appliation-layer-tony_chen - tieng vietEx 1 chapter03-appliation-layer-tony_chen - tieng viet
Ex 1 chapter03-appliation-layer-tony_chen - tieng viet
 
Cong nghnet
Cong nghnetCong nghnet
Cong nghnet
 
Tìm hiểu web service
Tìm hiểu web serviceTìm hiểu web service
Tìm hiểu web service
 
1 giới thiệu-cài đặt oracle
1 giới thiệu-cài đặt oracle1 giới thiệu-cài đặt oracle
1 giới thiệu-cài đặt oracle
 
Ldap introduce
Ldap introduceLdap introduce
Ldap introduce
 
J2 me 07_1
J2 me 07_1J2 me 07_1
J2 me 07_1
 
04 de cuong
04 de cuong04 de cuong
04 de cuong
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳ
 
Webservice
WebserviceWebservice
Webservice
 
LINQ TO XML
LINQ TO XMLLINQ TO XML
LINQ TO XML
 
Asp.net 3.5 _1
Asp.net 3.5 _1Asp.net 3.5 _1
Asp.net 3.5 _1
 
Asp control
Asp controlAsp control
Asp control
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳ
 
Báo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳBáo cáo thực tập cuối kỳ
Báo cáo thực tập cuối kỳ
 

More from Son Nguyen

Wsdl connector introduction
Wsdl connector introductionWsdl connector introduction
Wsdl connector introductionSon Nguyen
 
Android intergrate with mule
Android intergrate with muleAndroid intergrate with mule
Android intergrate with muleSon Nguyen
 
Mule flow overview
Mule flow overviewMule flow overview
Mule flow overviewSon Nguyen
 
Mule flow and filter
Mule flow and filterMule flow and filter
Mule flow and filterSon Nguyen
 
Handle exceptions in mule
Handle exceptions in muleHandle exceptions in mule
Handle exceptions in muleSon Nguyen
 
Spring security integrate with mule
Spring security integrate with muleSpring security integrate with mule
Spring security integrate with muleSon Nguyen
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in muleSon Nguyen
 
Expression language in mule
Expression language in muleExpression language in mule
Expression language in muleSon Nguyen
 
Mule with data weave
Mule with data weaveMule with data weave
Mule with data weaveSon Nguyen
 
Using spring scheduler mule
Using spring scheduler muleUsing spring scheduler mule
Using spring scheduler muleSon Nguyen
 
Composite source in bound and out-bound
Composite source in bound and out-boundComposite source in bound and out-bound
Composite source in bound and out-boundSon Nguyen
 
Batch job processing
Batch job processingBatch job processing
Batch job processingSon Nguyen
 
Using message enricher
Using message enricherUsing message enricher
Using message enricherSon Nguyen
 
Finance connectors with mule
Finance connectors with muleFinance connectors with mule
Finance connectors with muleSon Nguyen
 
Google drive connection
Google drive connectionGoogle drive connection
Google drive connectionSon Nguyen
 
Using properties in mule
Using properties in muleUsing properties in mule
Using properties in muleSon Nguyen
 
Mule integrate with microsoft
Mule integrate with microsoftMule integrate with microsoft
Mule integrate with microsoftSon Nguyen
 
Anypoint connectors
Anypoint connectorsAnypoint connectors
Anypoint connectorsSon Nguyen
 
Mule esb basic introduction
Mule esb basic introductionMule esb basic introduction
Mule esb basic introductionSon Nguyen
 

More from Son Nguyen (20)

Wsdl connector introduction
Wsdl connector introductionWsdl connector introduction
Wsdl connector introduction
 
Android intergrate with mule
Android intergrate with muleAndroid intergrate with mule
Android intergrate with mule
 
Mule flow overview
Mule flow overviewMule flow overview
Mule flow overview
 
Mule flow and filter
Mule flow and filterMule flow and filter
Mule flow and filter
 
Handle exceptions in mule
Handle exceptions in muleHandle exceptions in mule
Handle exceptions in mule
 
Spring security integrate with mule
Spring security integrate with muleSpring security integrate with mule
Spring security integrate with mule
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in mule
 
Expression language in mule
Expression language in muleExpression language in mule
Expression language in mule
 
Mule with data weave
Mule with data weaveMule with data weave
Mule with data weave
 
Using spring scheduler mule
Using spring scheduler muleUsing spring scheduler mule
Using spring scheduler mule
 
Composite source in bound and out-bound
Composite source in bound and out-boundComposite source in bound and out-bound
Composite source in bound and out-bound
 
Batch job processing
Batch job processingBatch job processing
Batch job processing
 
Using message enricher
Using message enricherUsing message enricher
Using message enricher
 
Finance connectors with mule
Finance connectors with muleFinance connectors with mule
Finance connectors with mule
 
Google drive connection
Google drive connectionGoogle drive connection
Google drive connection
 
Using properties in mule
Using properties in muleUsing properties in mule
Using properties in mule
 
Mule integrate with microsoft
Mule integrate with microsoftMule integrate with microsoft
Mule integrate with microsoft
 
Jms queue
Jms queueJms queue
Jms queue
 
Anypoint connectors
Anypoint connectorsAnypoint connectors
Anypoint connectors
 
Mule esb basic introduction
Mule esb basic introductionMule esb basic introduction
Mule esb basic introduction
 

ứNg dụng xml

  • 1. Lập trình mạng – Chương 7 1 ỨNG DỤNG XML TRONG LẬP TRÌNH MẠNG 1.1 Giới thiệu ngôn ngữ XML 1.2 XML trong các ứng dụng mạng 1.3 Một số ví dụ.
  • 2. Lập trình mạng – Chương 7 2 1.1 Giới thiệu ngôn ngữ XML • XML (Extensible Markup Language) là tập con của SGML (Standard Generalized Markup Language), được đơn giản hóa để hướng tới web. • Các đặc điểm: • Meaningful Searches • XML/EDI (XML for Electronic Data Interchange) • Enterprise Application Integration • Data accessibility/ Application simplification
  • 3. Lập trình mạng – Chương 7 3 1.1 Giới thiệu ngôn ngữ XML • So sánh HTML và XML: • Đều là tập con của SGML • HTML định dạng các tag để hiển thị, XML định dạng các tag thể hiện ngữ nghĩa dữ liệu. • XML hướng đến việc xử lý dữ liệu ở client. • XML có thể làm dữ liệu trao đổi giữa các ứng dụng trên Internet. • XML có thể dùng để lưu trữ dữ liệu như một database.
  • 4. Lập trình mạng – Chương 7 4 1.1 Giới thiệu ngôn ngữ XML • Cấu trúc file XML: • Được định nghĩa dựa vào các tags theo cấu trúc phân cấp. • Các tag do người sử dụng đặt • Tags và cấu trúc XML được định nghĩa theo DTD (Document Type Definition) hoặc XML Schema
  • 5. Lập trình mạng – Chương 7 5 1.1 Giới thiệu ngôn ngữ XML • Ví dụ file XML đơn giản: <?xml version="1.0"?> <!DOCTYPE personals SYSTEM "personal.dtd"> <personals> <person id="N.URAMOTO"> <name><family>URAMOTO</family> <given>Naohiko</given></name> <email>uramoto@jp.ibm.com</email> <link manager=" H.MARUYAMA"/> </person> <person id="K.TAMURA"> <name> <family>TAMURA</family> <given>Kent</given> </name> <!-- This URL is mail address.--> <url href="mailto:kent@trl.ibm.co.jp"/> <url href="mailto:tkent@jp.ibm.com"/> <link manager="H.MARUYAMA"/> </person> </personals>
  • 6. Lập trình mạng – Chương 7 6 1.1 Giới thiệu ngôn ngữ XML • DTD: <?xml encoding="US-ASCII"?> <!ELEMENT personals (person)+> <!ELEMENT person (name,email*,url*,link?)> <!ATTLIST person id ID #REQUIRED> <!ELEMENT family (#PCDATA)> <!ELEMENT given (#PCDATA)> <!ELEMENT name (#PCDATA|family|given)*> <!ELEMENT email (#PCDATA)> <!ELEMENT url EMPTY> <!ATTLIST url href CDATA #REQUIRED> <!ELEMENT link EMPTY> <!ATTLIST link manager IDREF #IMPLIED subordinates IDREFS #IMPLIED>
  • 7. Lập trình mạng – Chương 7 7 1.1 Giới thiệu ngôn ngữ XML • Truy xuất các phần tử trong file XML: • Có thể sử dụng bất cứ ngôn ngữ lập trình trên các platform khác nhau. • Các cách truy xuất đã được W3C(www.w3c.org) định nghĩa • Document Object Model(DOM) • XPointer • XML StyleSheet Language(XSL) • XML Query Language(XQL) • …
  • 8. Lập trình mạng – Chương 7 8 1.2 XML trong các ứng dụng mạng • Định nghĩa các format dữ liệu để trao đổi: • Cấu trúc file XML với DTD hay XML Schema quy định về protocol giao tiếp. • Dữ liệu được biểu diễn theo các tag. • Là môi trường để các hệ thống không đồng nhất có thể giao tiếp với nhau. • Hệ thống cho phép mở rộng nhiều đối tượng tham gia, mở rộng giao dịch mà không ảnh hưởng đến các giao dịch cũ. • Có thể truyền qua giao thức HTTP
  • 9. Lập trình mạng – Chương 7 9 1.2 XML trong các ứng dụng mạng • Ví dụ mô hình giao dịch ngân hàng: XML Bank C Bank B Bank A
  • 10. Lập trình mạng – Chương 7 10 1.2 XML trong các ứng dụng mạng • Các công nghệ dựa trên XML được sử dụng hiện nay: • Simple Object Access Protocol(SOAP) • Các dữ liệu XML được truyền qua giao thức HTTP như một đối tượng. • Web services • Chuẩn XML được hỗ trợ để truyền giữa các ứng dụng web để trao đổi dữ liệu. • Microsoft .NET Framework
  • 11. Lập trình mạng – Chương 7 11 1.3 Một số ví dụ 1. import org.apache.xerces.parsers.DOMParser; 2. import org.apache.xml.serialize.*;import org.w3c.dom.*; 3. import org.xml.sax.*; 4. private Document document; 5. private Node root; 6. private DOMParser parser = new DOMParser(); 7. try 8. { 9. //pre-parse 10. ByteArrayInputStream input = new ByteArrayInputStream(inBuffer); 11. parser.setFeature("http://apache.org/xml/"+ 12. "features/dom/include-ignorable-whitespace",false); 13. parser.parse(new InputSource(input)); 14. document=parser.getDocument(); 15. //Set DOCTYPE for input document 16. OutputFormat format=new OutputFormat(); 17. format.setDoctype(null,"requestInformation.dtd");
  • 12. Lập trình mạng – Chương 7 12 18. ByteArrayOutputStream output = new ByteArrayOutputStream(); 19. XMLSerializer serial =new XMLSerializer(output,format); 20. serial.serialize(document); 21. inBuffer = output.toByteArray(); 22. //real-parse 23. input = new ByteArrayInputStream(inBuffer); 24. parser.reset(); 25. parser.parse(new InputSource(input)); 26. document=parser.getDocument(); 27. root = this.document.getDocumentElement(); 28. 29. //Get information 30. Node cardNumberNode = root.getFirstChild(); 31. cardNumber = cardNumberNode.getFirstChild().getNodeValue(); 32. cardNumber = this.cardNumber.trim(); 33. }catch (Exception e){}