Reposted from: success,
After all, instead of making the ASPX page access the database every time it accesses the database, open the data connection, and close the data connection,
It is better to save data as an HTM static page.
I have been searching for this information on the Internet. I also went to msdn to look at the class library, one method and one method, and finally managed to gain a glimpse.
Come on!
Three files are required: XML, XSL, and Aspx.Program
Listing8.8.2.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Golfers>
<Golfer skill = "excellent" handicap = "10" clubs = "Taylor made" id = "1111">
<Name>
<Firstname> Bu qingcloud </firstname>
<Lastname> Frey </lastname>
</Name>
</Golfer>
<Golfer skill = "moderate" handicap = "12" clubs = "Taylor made" id = "2222">
<Name>
<Firstname> Frey </firstname>
<Lastname> Glenn </lastname>
</Name>
</Golfer>
</Golfers>
listing8.8.1.xsl
my name:
.
Finally, the aspx program page listing8.5.aspx
<% @ Import namespace = "system. xml" %>
<% @ Import namespace = "system. xml. XSL" %>
<% @ Import namespace = "system. xml. XPath" %>
<% @ Import namespace = "system. Io" %>
<Script language = "VB" runat = "server">
Public sub page_load (sender as object, e as eventargs)
Dim xmlpath as string = server. mappath ("listing8.2.xml ")
Dim export path as string = server. mappath ("listing8.1.xsl ")
Dim htmpath as string = server. mappath ("listing8.1.htm ")
Dim FS as filestream = new filestream (xmlpath, filemode. Open, fileaccess. Read)
Dim reader as streamreader = new streamreader (FS, encoding. utf8)
Dim xmlreader as xmltextreader = new xmltextreader (Reader)
Dim fstr as filestream = new filestream (htmpath, filemode. Create)
Dim doc as xpathdocument = new xpathdocument (xmlreader)
Dim ‑doc as ‑transform = new ‑transform ()
Using Doc. Load (using path)
'Convert data
Using Doc. Transform (Doc, nothing, fstr, nothing)
Export Doc. Transform (Doc, nothing, response. Output) ''output to the page
'Close the opened object
FS. Close ()
Reader. Close ()
Xmlreader. Close ()
Fstr. Close ()
End sub
</SCRIPT> C # Code : Code
String Xmlpath = Server. mappath ( " Listing. xml " );
String Export path = Server. mappath ( " Listing. XSL " );
String Htmlpath = Server. mappath ( " Listing.htm " );
Filestream FS = New Filestream (xmlpath, filemode. Open, fileaccess. Read );
Streamreader = New Streamreader (FS, encoding. utf8 );
Xmltextreader xmlreader = New Xmltextreader (Reader );
Filestream fstr = New Filestream (htmlpath, filemode. Create );
xpathdocument xpathdoc = New xpathdocument (xmlreader );
compile compiledtransform transform = New extends compiledtransform ();
transform. load (export path);
transform. transform (xpathdoc, null , fstr);
/// transform. transform (xpathdoc, null, response. output);
FS. close ();
reader. close ();
xmlreader. close ();
fstr. close ();
the generated HTM file is as follows:
listing8.1.htm
what does my name mean:
1.
Bu qingcloud
2.
Frey