09/10/2018, 23:49
Hỏi về ASP dùng database XML
Cho em hỏi, làm sao để mình connect cơ sở dữ liệu XML vào một form
ví dụ như lấy các note trong XML bỏ vào form select chằng hạng
form ASP
<select name="sss">
<option>lấy từ XML </option>
<option>lấy từ XML </option>
</select>
File xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="tool.xsl"?>
<tool>
<field id="prodName">
<value>TI VI SAMSUM 17 INCH </value>
</field>
<field id="prodNo">
<value>123456</value>
</field>
<field id="price">
<value>60.000</value>
</field>
<field id="nsx">
<value>May Lanh </value>
</field>
<field id="nsxno">
<value>654321</value>
</field>
<field id="gia">
<value>60.000</value>
</field>
</tool>
Có tài liệu nào nói về chuyện đó không nhỉ >
ví dụ như lấy các note trong XML bỏ vào form select chằng hạng
form ASP
<select name="sss">
<option>lấy từ XML </option>
<option>lấy từ XML </option>
</select>
File xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="tool.xsl"?>
<tool>
<field id="prodName">
<value>TI VI SAMSUM 17 INCH </value>
</field>
<field id="prodNo">
<value>123456</value>
</field>
<field id="price">
<value>60.000</value>
</field>
<field id="nsx">
<value>May Lanh </value>
</field>
<field id="nsxno">
<value>654321</value>
</field>
<field id="gia">
<value>60.000</value>
</field>
</tool>
Có tài liệu nào nói về chuyện đó không nhỉ >
Bài liên quan
Trong .net có sẵn abstract class XmlTextReader đọc tuần tự nếu file xml bạn lớn ! Không biết file xml của bạn thế nào nhưng xml sinh ra ko phải để phục vụ việc lưu dữ liệu nên hãy cân nhắc trước khi làm!
Với dot Net thì chuyện kết nối, sử lí XML là nhỏ như con thỏ, nhưng với ASP Classic thì là cả một vấn đề đó
Code sau hi vọng giúp đc bạn:
File xml có cấu trúc sau: Đặt tên là Page.xml
<?xml version="1.0"?>
<main>
<title>Our Page.xml file</title>
<heading>This is a test heading</heading>
<paragraph>This is our paragraph and you can write whatever
you want to in this space.</paragraph>
<testHTML><![CDATA[We will enclose some HTML code in CDATA section now :<br>
<table width="60%" border="1" bordercolor="silver" cellspacing="2"
cellpadding="3">
<tr>
<td>
You can write any HTML code or for that matter any type of text inside
the CDATA section without a fear of getting any error.<br><br>
Note if we write this without the CDATA tags, the xml parser will
raise an error and won't show the document.
</td>
</tr>
</table>]]></testHTML>
</main>
<%
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load (Server.MapPath("page.xml"))
Dim title, heading, paragraph, testHTML
title = xml.documentElement.childNodes(0).text
heading = xml.documentElement.childNodes(1).text
paragraph = xml.documentElement.childNodes(2).text
testHTML = xml.documentElement.childNodes(3).text
Set xml = Nothing
%>
<html>
<head>
<title><%= title %></title>
</head>
<body>
<h3 align="center"><%= heading %></h3>
<p align="center"><% = paragraph %></p>
<div align="center"><%= testHTML %></div>
</body>
</html>
xml.async = False -> Để false tức là ta hiện thị dữ liệu(read it) chứ ko phải để ghi, nên đặt false để tăng tốc độ xử lý!
bạn ơi có thể chỉ mình cách dùng dom ko de dọc file xml dó