Tạo HTML từ XML và XSL
Số trang: 3
Loại file: pdf
Dung lượng: 122.76 KB
Lượt xem: 2
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tạo HTML từ XML và XSL Thông thường, nếu bạn định nghĩa bên trong một XML file rằng nó cần một XSL để display thì Internet Exporer 5.5 sẽ tự transform XML dựa theo XSL và display kết quả trong browser cho bạn.
Nội dung trích xuất từ tài liệu:
Tạo HTML từ XML và XSL Tạo HTML từ XML và XSLThông thường, nếu bạn định nghĩa bên trong một XML file rằng nó cần một XSL đểdisplay thì Internet Exporer 5.5 sẽ tự transform XML dựa theo XSL và display kết quảtrong browser cho bạn. Trong trường hợp ấy nếu bạn View Source của Webpage bạn chỉđọc đuợc XML source mà thôi. Có thể bạn sẽ thắc mắc sao không thấy cái HTML sourcelà kết quả của quá trình Tranform XML.Trong chương trình VB6 trình bày tại đây bạn sẽ thấy cách dùng DOM (DocumentObject Model) của MSXML để thực hiện công việc tương đương với IE 5.5 và save kếtquả HTML thành một Webpage . Webpage nầy có thể được display, độc lập với XML,bằng bất cứ WebBrowser nào.Thật ra, ActiveX MSXML mà ta dùng cho VB6 là của IE5.5 khi ta Project | Reference Microsoft XML, v3.0.Chương trình mẫuBạn có thể download chương trình mẫu TransformXML.zip để xem cách thảo chươngrất đơn giản.Phần chính của chương trình nằm trong Sub Form_Load như liệt ra dưới đây. Bạn có thểxem listing và giải thích về cách transform Library.xml dựa trên Library.xsl trong bàiXML, Kỹ thuật tin học nòng cốt trong tương lai.Private Sub Form_Load() Dim HTMLCode As String Need to Project | References Microsoft XML, v3.0 to use DOM Dim myXMLDoc As New MSXML2.DOMDocument30 Dim myXSLDoc As New MSXML2.DOMDocument30 Need to Project | References Microsoft Script Runtime to use FileSystemObject and TextStream Dim Fs As FileSystemObject Dim TS As TextStream Display the XML file in a listbox PopulateListBoxFromFile LstXML, Library.xml, False Display the XSL file in a listbox PopulateListBoxFromFile lstXSL, Library.xsl, False Load the XML file myXMLDoc.Load App.Path & \Library.xml Load the XSL file myXSLDoc.Load App.Path & \Library.xsl Transform XML by XSL to give HTML HTMLCode = myXMLDoc.transformNode(myXSLDoc) Now Write the resultant HTML to file Create a FileSystem Object Set Fs = CreateObject(Scripting.FileSystemObject) Open TextStream for Output Set TS = Fs.OpenTextFile(App.Path & \Library.htm, ForWriting, False,TristateUseDefault) TS.Write HTMLCode Write the whole HTML string in one stroke TS.Close Close the Text Stream Set Fs = Nothing Dispose FileSystem Object Display the HTML file in a listbox PopulateListBoxFromFile lstHTML, Library.htm, FalseEnd Sub
Nội dung trích xuất từ tài liệu:
Tạo HTML từ XML và XSL Tạo HTML từ XML và XSLThông thường, nếu bạn định nghĩa bên trong một XML file rằng nó cần một XSL đểdisplay thì Internet Exporer 5.5 sẽ tự transform XML dựa theo XSL và display kết quảtrong browser cho bạn. Trong trường hợp ấy nếu bạn View Source của Webpage bạn chỉđọc đuợc XML source mà thôi. Có thể bạn sẽ thắc mắc sao không thấy cái HTML sourcelà kết quả của quá trình Tranform XML.Trong chương trình VB6 trình bày tại đây bạn sẽ thấy cách dùng DOM (DocumentObject Model) của MSXML để thực hiện công việc tương đương với IE 5.5 và save kếtquả HTML thành một Webpage . Webpage nầy có thể được display, độc lập với XML,bằng bất cứ WebBrowser nào.Thật ra, ActiveX MSXML mà ta dùng cho VB6 là của IE5.5 khi ta Project | Reference Microsoft XML, v3.0.Chương trình mẫuBạn có thể download chương trình mẫu TransformXML.zip để xem cách thảo chươngrất đơn giản.Phần chính của chương trình nằm trong Sub Form_Load như liệt ra dưới đây. Bạn có thểxem listing và giải thích về cách transform Library.xml dựa trên Library.xsl trong bàiXML, Kỹ thuật tin học nòng cốt trong tương lai.Private Sub Form_Load() Dim HTMLCode As String Need to Project | References Microsoft XML, v3.0 to use DOM Dim myXMLDoc As New MSXML2.DOMDocument30 Dim myXSLDoc As New MSXML2.DOMDocument30 Need to Project | References Microsoft Script Runtime to use FileSystemObject and TextStream Dim Fs As FileSystemObject Dim TS As TextStream Display the XML file in a listbox PopulateListBoxFromFile LstXML, Library.xml, False Display the XSL file in a listbox PopulateListBoxFromFile lstXSL, Library.xsl, False Load the XML file myXMLDoc.Load App.Path & \Library.xml Load the XSL file myXSLDoc.Load App.Path & \Library.xsl Transform XML by XSL to give HTML HTMLCode = myXMLDoc.transformNode(myXSLDoc) Now Write the resultant HTML to file Create a FileSystem Object Set Fs = CreateObject(Scripting.FileSystemObject) Open TextStream for Output Set TS = Fs.OpenTextFile(App.Path & \Library.htm, ForWriting, False,TristateUseDefault) TS.Write HTMLCode Write the whole HTML string in one stroke TS.Close Close the Text Stream Set Fs = Nothing Dispose FileSystem Object Display the HTML file in a listbox PopulateListBoxFromFile lstHTML, Library.htm, FalseEnd Sub
Gợi ý tài liệu liên quan:
-
52 trang 430 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 314 0 0 -
74 trang 296 0 0
-
96 trang 293 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 289 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 281 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 275 0 0 -
Tài liệu dạy học môn Tin học trong chương trình đào tạo trình độ cao đẳng
348 trang 269 1 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 265 0 0 -
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 264 0 0