How does. Net (C #) generate xml?
XML generated by. Net: menu. xml
<Root>
<Treenode Title = "zeditor1" href = "http://www.google.cn/" target = "_ blank">
<Treenode Title = "zeditor01" href = http://www.yahoo.com.cn/"target =" _ blank "/>
</Treenode>
<Treenode Title = "zeditor2" href = "http://www.baidu.com/target =" _ blank "/>
</Root>
XSLT: sitemenu. XSL
<? XML version = "1.0" encoding = "UTF-8"?>
<XSL: stylesheetversion = "1.0"
Xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: template match = "root">
<XSL: Apply-templates/>
</XSL: Template>
<XSL: template match = "treenode">
<Ul style = "list-style: none; margin: 0px 20px;">
<XSL: For-each select = ".">
<Li style = "list-style: none;">
<A>
<XSL: attribute name = "href">
<XSL: value-of select = "@ href"/>
</XSL: attribute>
<XSL: attribute name = "target">
<XSL: value-of select = "@ target"/>
</XSL: attribute>
<XSL: value-of select = "@ title"/>
</A>
<XSL: Apply-templates/>
</LI>
</XSL: For-each>
</Ul>
</XSL: Template>
</XSL: stylesheet>
After generation, parse through JS:
Loadxml ("menu. XML," sitemenu. XSL ");
Function loadxml (xmlf, xslf)
{
Try
{
VaR myxml = new activexobject ("msxml2.freethreadeddomdocument ");
Myxml. async = false;
Myxml. Load (xmlf );
VaR myxsl = new activexobject ("msxml2.freethreadeddomdocument ");
Myxsl. async = false;
Myxsl. Load (using F );
Html = myxml. transformnode (myxsl );
Document. Write (HTML );
}
Catch (exception)
{
Alert (exception. Description );
}
}