Asp.net|xml| problem units need to update the previous news system, need to connect with the modern society, so began to study the XML to store the news method.
Found a very famous on the Internet to read the XML file as a news method, the code is as follows:
<%@ Import namespace= "System"%>
<%@ Page language= "C #" debug= "true" codepage= "936"%>
<%@ Import namespace= "System.IO"%>
<%@ Assembly name= "System.Xml"%>
<%@ Import namespace= "SYSTEM.XML.XSL"%>
<title>
</title>
<script language= "C #" runat= "Server" >
public string XSLT ()
{
StringWriter writer = new StringWriter ();
XslTransform Xsldoc = new XslTransform ();
Xsldoc. Load (Server.MapPath ("main.xsl"));
Documentnavigator nav= New Documentnavigator (xmldoc);
Xsldoc. Transform (Nav,null,writer);
return writer. ToString ();
}
</script>
<body>
<%=XSLT ()%>
<p align= "Center" > The program was made by <a href= "http://www.aspcool.com" >www.aspcool.com</a> design .</p>
</body>
The key is:
Documentnavigator nav= New Documentnavigator (xmldoc);
This sentence can not explain how, depressed for a long time, looking for the latest MSDN Lib results to find a 2001-year MSDN Magazine above the passage:
Documentnavigator can only be used for asp.net Beta2, pain, for a long time, this so-called classic code unexpectedly is outdated products.
There is no way, but from the last sentence to find ways to
Xsldoc. Transform (Nav,null,writer);
Finally found the use of transform this function,
Public XmlReader Transform (
XPathNavigator input,
XsltArgumentList args
);
And then started looking for XPathNavigator, well, XmlDocument himself with a createnavigator () function.
It's done.
Modified code:
<%@ Import namespace= "System"%>
<%@ Page language= "C #" debug= "true" codepage= "936"%>
<%@ Import namespace= "System.IO"%>
<%@ Assembly name= "System.Xml"%>
<%@ Import namespace= "System.Xml"%>
<%@ Import namespace= "SYSTEM.XML.XSL"%>
<%@ Import namespace= "System.Xml.XPath"%>
<title>
</title>
<script language= "C #" runat= "Server" >
public string XSLT ()
{
StringWriter writer = new StringWriter ();
Search for a night of Google did not find the results, or to their own analysis, I hope that this code can be found in Google, so that the future to learn asp.net of the like-minded people do not spend too much time to think, can find the answer as soon as possible.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.