菜鸟提问!我想在用xml + xsl 来生成web页面,但是总报"这是一个意外的标记。标记应为“NAME”。 行 2,位置 73。 "
如题:
这是一个意外的标记。标记应为“NAME”。 行 2,位置 73。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Xml.XmlException: 这是一个意外的标记。标记应为“NAME”。 行 2,位置 73。
以下是adorset.xml
<?xml version="1.0" standalone="yes" ?>
<NewDataSet>
<tbButton>
<Button>
<id>CN</id>
<text><asp:Button id="btnCN" runat="server" Text="中文按钮按" Width="112px"></asp:Button></text>
</Button>
<Button>
<id>EN</id>
<text><asp:Button id="btnEN" runat="server" Text="EnglishButton" Width="120px"></asp:Button></text>
</Button>
</tbButton>
</NewDataSet>
以下是xsl1.xsl:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform "version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:myutils="http://mycoolplace.com">
<xsl:template match="NewDataSet">
<TABLE>
<xsl:apply-templates select="NewDataSet/tbButton/Button"/>
</TABLE>
</xsl:template>
<xsl:template match="Button">
<TR>
<TD> <xsl:value-of select="text" disable-output-escaping="yes"/></TD>
</TR>
</xsl:template>
</xsl:stylesheet>
以下是C#调用:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
ShowHtml();
Response.Redirect("show.xml");
}
}
private void ShowHtml()
{
string xmlpath = Server.MapPath("adorset.xml");
string xslpath = Server.MapPath("xsl1.xsl");
string output = Server.MapPath("show.xml");
Transform(xmlpath,xslpath,output);
}
private void Transform(string source,string stylesheet,string output)
{
try
{
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
xslt.Transform(source,output);
}
catch(Exception exp)
{
throw exp;
}
}
麻烦大家看看吧,谢谢了
问题点数:200、回复次数:14Top
1 楼mapserver(杨东 http://mapserver.cnblogs.com)回复于 2005-08-01 23:44:52 得分 100
adorset.xml:
应该是<?xml version="1.0" encoding="GB2312" standalone="yes"?>吧。Top
2 楼Nicholasqpl(【快乐|我灌我灌我灌灌灌|快乐】)回复于 2005-08-01 23:47:51 得分 0
to: mapserver(杨东)
试过了,还是老样子.急啊Top
3 楼mapserver(杨东 http://mapserver.cnblogs.com)回复于 2005-08-01 23:52:49 得分 0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform "version="1.0"
—〉
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform " version="1.0"
你把你的xml和xsl放在同一文件夹下,用ie打开看看哪里报错就知道了。Top
4 楼mapserver(杨东 http://mapserver.cnblogs.com)回复于 2005-08-01 23:53:12 得分 0
version前面有个空格的。Top
5 楼Nicholasqpl(【快乐|我灌我灌我灌灌灌|快乐】)回复于 2005-08-02 00:00:27 得分 0
呵呵..是version前面少了个空格Top
6 楼Nicholasqpl(【快乐|我灌我灌我灌灌灌|快乐】)回复于 2005-08-02 00:01:29 得分 0
都是拷贝惹的祸啊..Top
7 楼mapserver(杨东 http://mapserver.cnblogs.com)回复于 2005-08-02 00:01:30 得分 0
哈哈,我也老是犯这样的低级错误。Top
8 楼mapserver(杨东 http://mapserver.cnblogs.com)回复于 2005-08-02 00:05:55 得分 0
可以先用ie来验证xml和xsl的格式是否正确,这样很容易定位到底是xml文件格式错误还是程序写的有错误。Top
9 楼saucer(思归)回复于 2005-08-02 00:17:32 得分 40
1. besides the space problem, your xslt is also wrong,
<xsl:template match="NewDataSet">
<TABLE>
<xsl:apply-templates select="tbButton/Button"/>
</TABLE>
</xsl:template>
2. also, you shouldn't use < and > you should use straight < />, since controls need to have an end or closing tag
3. you are dynamically creating .xml files with <runat=server> controls in it? why?
Top
10 楼dsclub(任搏软)回复于 2005-08-02 00:23:53 得分 20
1.xml
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="1.xsl"?>
<NewDataSet>
<tbButton>
<Button>
<id>CN</id>
<text><asp:Button id="btnCN" runat="server" Text="中文按钮" Width="112px"></asp:Button></text>
</Button>
<Button>
<id>EN</id>
<text><asp:Button id="btnEN" runat="server" Text="EnglishButton" Width="120px"></asp:Button></text>
</Button>
</tbButton>
</NewDataSet>
1.xsl
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" version="4.0" encoding="GB2312"/>
<xsl:template match="/">
<TABLE border="1">
<xsl:apply-templates select="./NewDataSet/tbButton/Button"/>
</TABLE>
</xsl:template>
<xsl:template match="Button">
<TR>
<TD> <xsl:value-of select="./text"/></TD>
</TR>
</xsl:template>
</xsl:stylesheet>Top
11 楼dsclub(任搏软)回复于 2005-08-02 00:28:44 得分 0
以上是验证xsl的,保存两个文件到同一目录下,用ie浏览1.xml即可看到效果,这样xsl是正确的。
建议楼主多看看X-Path和xslt的一些基本指令。
另外,如果想解析出html标签来
http://www.cnblogs.com/dsclub/archive/2004/08/19/34661.htmlTop
12 楼dsclub(任搏软)回复于 2005-08-02 00:30:41 得分 0
最后如果是使用DotNet的XslTransform来在Server上解析的话不用要<xsl:output method="html" version="4.0" encoding="GB2312"/>这句了Top
13 楼Sunmast(速马@Redmond, WA)回复于 2005-08-02 00:37:51 得分 20
用xslt做web会累死人的,嗯,完全的不推荐Top
14 楼zeusvenus()回复于 2005-08-02 07:46:51 得分 20
别这样拷贝了,出N多问题。Top
相关问题
- 能否通过xml和xsl生成html时产生"<%%>"???
- 如何用JSP将XML和XSL生成HTML ?
- 求asp+xml+xsl生成的无限级分类开合菜单
- 读xml,生成html?
- dom4j生成xml文件问题,怎么加一个“<?xml-stylesheet type="text/xsl" href="xslfile.xsl"?>”
- Mozilla不支持disable-output-escaping,该怎样用XSL解释XML中的HTML标记?
- 如何分析HTML文件,生成一棵标记树?
- 如何用javascript动态生成一个标记?
- 紧急!!关于用asp动态生成xml,如何使用xsl样式表
- 有一xml文件和一xsl文件,如何生成一个文本文件




