dom & sax xml & ado.net
DESCRIPTION
DOM & SAX XML & ADO.NET. GVTH: Phạm Anh Phương Email : [email protected]. Thời gian. 20 minutes. Tham khảo. Websites : http://www.codeproject.com/cs/database/ADONET_and_XML.asp http://www.w3.org/XML http://www.xml.org - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/2.jpg)
Thời gianThời gian
20 minutes
![Page 3: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/3.jpg)
Tham khảoTham khảo
Websites :
http://www.codeproject.com/cs/database/ADONET_and_XML.asp
http://www.w3.org/XML
http://www.xml.org
http://www.informit.com/guides/content.asp?g=dotnet&seqNum=80&rl=1
Thư viện MSDN
Ebooks :
1/ The.Book.of.SAX-The.Simple.API.for.XML.pdf
2/ MS.Press.Applied.XML.Programming.For.Microsoft.Dot.NET.eBook-LiB.chm
![Page 4: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/4.jpg)
Mục lụcMục lục
DOM & SAX
XML & ADO.NET
XMLDocument
![Page 5: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/5.jpg)
DOMDOM
![Page 6: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/6.jpg)
DOM là gì ?DOM là gì ?
The W3C Document Object Model (DOM) is a platform and language-neutral interfaceinterface that allows programs and scripts to dynamically access and update the content, structure, and style of a document
Interface
![Page 7: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/7.jpg)
DOM là gì ?DOM là gì ?
Core DOM
XML DOM
HTML DOM
DOM được chia gồm 3 phần riêng biệt :
Là tập đối tượng thao tác với tài liệu có cấu trúc, XML, HTML
![Page 8: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/8.jpg)
<< Interface >><< Interface >>DOMDOM
XML ParserXML Parser HTML ParserHTML Parser
(.NET, .JAVA,..) (IE 6, Firefox, ..)
XXX ParserXXX Parser
DOM là gì ?DOM là gì ?
![Page 9: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/9.jpg)
DOM xem tài liệu XML như 1 cây có cấu trúc
Tất cả Element, Attribute, Text đều có thể truy xuất (thêm, xóa và sửa)
Element, Attribute, Text được xem là Node
Tài liệu XML là 1 Node Tree
XML DOM là gì ?XML DOM là gì ?
<?xml version="1.0" ><name> <first>Phuong</first> <middle>Anh</middle> <last>Pham</last></name>
middle
Name
first
last
Phuong
Anh
Pham
![Page 10: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/10.jpg)
Một cây gồm nhiều node dùng để thể hiện 1 tài liệu XML và sự kết nối giữa chúng- Trong cây, node cao nhất gọi là root- Mỗi node, trừ root ra có chính xác 1 node cha- Một node có nhiều node con- Node lá là node không có node con- Siblings là những node có cùng cấp với node cha
Node TreeNode Tree
![Page 11: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/11.jpg)
Để đọc, cập nhật, tạo và thao tác 1 tài liệu XML ta cần 1 XML Parser
Có nhiều XML Parser được hỗ trợ trong hầu hết các ngôn ngữ (JAVA, JavaScript, .NET, ..)
Parser nạp tài liệu XML vào trong bộ nhớ máy tính và được xem dưới dạng cây Node
Sau đó, dữ liệu được thao tác và xử lý thông qua tập hàm XML DOM API
XML DOM ParserXML DOM Parser
![Page 12: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/12.jpg)
XML DOM ParserXML DOM Parser
XML DOM API
![Page 13: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/13.jpg)
XML DOM APIXML DOM API
Duyệt các nodes :
- parentNode- childNodes- firstChild- lastChild- nextSibling- previousSibling
Root Element :<bookstore>
Element :<book>
Element :<book>
Element :<book>
Element :<book>
parentNode
lastChild
nextSibling
previousSibling
firstChild
![Page 14: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/14.jpg)
Thao tác các Node:- getElementsByTagName- getElmentById- getNamedItem- setAttribute- getAttribute- removeChild- removeAttribute- replaceChild- ..
XML DOM APIXML DOM API
![Page 15: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/15.jpg)
SAX SAX
![Page 16: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/16.jpg)
SAX (Simple API for XML) Performance và Memory không bị ảnh
hưởng cho dù thao tác với tài liệu XML có dung lượng lớn
Event-Driven API
SAXSAX
![Page 17: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/17.jpg)
SAXSAX
![Page 18: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/18.jpg)
Xử lý dữ liệu ngay khi Parser chưa xử lý tòan bộ tài liệu XML (Khác so với DOM)
Dữ liệu sau khi được parse sẽ gửi đến Client Program thông qua các hàm Notification Method; dữ liệu này sau đó bị xóa
SAXSAX
![Page 19: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/19.jpg)
SAX được hỗ trợ trong JAVA nhưng chưa có trong .NET
Khuyết điểm:- Developer phải tạo cấu trúc lưu trữ thông tin
riêng vì dữ liệu gửi về từ parser sẽ tự động mất sau khi đến Notification Method
- SAX không phù hợp đối với các ứng dụng truy xuất ngẫu nhiên và thực hiện chỉnh sửa phức tạp
SAXSAX
![Page 20: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/20.jpg)
XMLDocumentXMLDocument
![Page 21: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/21.jpg)
Là đối tượng dùng để thao tác với tài liệu XML trong .NET
Namespace : System.Xml
XMLDocumentXMLDocument
![Page 22: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/22.jpg)
XMLDocumentXMLDocument
Tên hàm (Thuộc tính) Ý nghĩaLoad Nạp tài liệu XML
Save Ghi tài liệu XML
-InsertBefore, InsertAfter-PrependChild, AppendChild-RemoveChild, ReplaceChild, RemoveAll
Phương thức truy cập node
- NodeChanging, NodeChanged-NodeInserting, NodeInserted-NodeRemoving, NodeRemoved
Xử lý sự kiện thông qua các delegate
-FirstChild, LastChild-ChildNodes, NextSibling, PreviousSibling, ParentNode
Thao tác duyệt node
![Page 23: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/23.jpg)
XMLDocumentXMLDocument
Đọc và lưu
Lấy Root Element :
![Page 24: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/24.jpg)
XMLDocumentXMLDocument
Xóa Node
![Page 25: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/25.jpg)
XMLDocumentXMLDocument
Thêm Node
![Page 26: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/26.jpg)
XML & ADO.NETXML & ADO.NET
![Page 27: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/27.jpg)
Đối tượng : DataSet Ý nghĩa : Một Database nhưng được lưu trong
memory Thao tác :
- Tạo mối quan hệ giữa các bảng- Thêm, xóa, sửa các record trong bảng
Với XML :- Ghi dữ liệu thành file XML- Đọc dữ liệu từ file XML và nạp lại vào DataSet
XML & ADO.NETXML & ADO.NET
![Page 28: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/28.jpg)
Một số phương thức :- GetXml- GetXmlSchema- WriteXml- ReadXml- WriteXmlSchema- ReadXmlSchema
XML & ADO.NETXML & ADO.NET
![Page 29: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/29.jpg)
Minh họa :
XML & ADO.NETXML & ADO.NET
![Page 30: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/30.jpg)
Hỏi & ĐápHỏi & Đáp
![Page 31: DOM & SAX XML & ADO.NET](https://reader035.vdocuments.mx/reader035/viewer/2022070413/56814c4d550346895db9585e/html5/thumbnails/31.jpg)
Cảm ơnCảm ơn