问题描述
stringtempletURl="/Template/default/rest.htm";//简体中文Encodingencoding=Encoding.GetEncoding("utf-8");//读取模版文件stringhtmlmodel=Server.MapPath(templetURl);StreamReadersr=newStreamReader(htmlmodel,encoding);stringstr=sr.ReadToEnd();DBdb=newDB();//用返回table然后转换称xml的时候就报错了,但是查询的条数就没有限制stringsql="selecttop20newsid,title,fb_date,classnamefromNewsView";DataTabledt=db.GetTable(sql);MemoryStreamxmlStream=newMemoryStream();xmlStream.Position=0;dt.WriteXml(xmlStream,XmlWriteMode.IgnoreSchema);XmlReaderreader=newXmlTextReader(xmlStream);xmlStream.Flush();xmlStream.Close();XPathDocumentxpathDoc=newXPathDocument(reader);stringxslPath=Server.MapPath("Template/标签库/newsModel.xsl");XsltSettingssettings=newXsltSettings(true,true);XslCompiledTransformtransform=newXslCompiledTransform();transform.Load(xslPath,settings,null);//设置参数XsltArgumentListarg=newXsltArgumentList();arg.AddParam("displayDate","","true");arg.AddParam("dateformat","","MM月dd日");//设置调用的自定义方法Publicp=newPublic();arg.AddExtensionObject("public",p);StringWriterwriter=newStringWriter();transform.Transform(xpathDoc,arg,writer);reader.Close();sr.Close();str=str.Replace("标签",writer.ToString());Response.Write(str);我的代码一个xml+xsl生成页面的代码,但是在XPathDocumentxpathDoc=newXPathDocument(reader);这一句的时候报错了“/”应用程序中的服务器错误。缺少根元素。说明:执行当前Web请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。异常详细信息:System.Xml.XmlException:缺少根元素。源错误:行43:行44:行45:XPathDocumentxpathDoc=newXPathDocument(reader);行46:stringxslPath=Server.MapPath("Template/标签库/newsModel.xsl");行47:请各位大侠看一下都看了半天了都没解决
解决方案
解决方案二:
怎么木有人忙我解答一下呢