异常详细信息: System.NotSupportedException: 不支持给定路径的格式。源错误:
行 36: settings.ValidationType = ValidationType.Schema;
行 37: //把XSD添加到xmlreaderSettings 的Schmas 模式中
行 38: settings.Schemas.Add(null,XmlReader.Create(xsdPath));//????????????
行 39: reader = XmlReader.Create(xmlPath,settings);
行 40: while (reader.Read()) 源文件: c:\Inetpub\wwwroot\Chapter5\a.aspx.cs I 行: 38功能:用XSD模式验证xml数据
程序如下:
public partial class a : System.Web.UI.Page
{
//对CHAR有自动扩展的功能 private StringBuilder _builder = new StringBuilder();
protected void Page_Load(object sender, EventArgs e)
{
//httpRequest.page.Request 获取页面请求的对象
string xmlPath = Request.PhysicalApplicationPath + @"C:\Inetpub\wwwroot\Chapter5\Author.xml"; string xsdPath = Request.PhysicalApplicationPath + @"C:\Inetpub\wwwroot\Chapter5\Author.xsd";
XmlReader reader = null;
XmlReaderSettings settings = new XmlReaderSettings();
//set prooperty
settings.ValidationEventHandler += new ValidationEventHandler(this.ValidationEventHandler);
settings.ValidationType = ValidationType.Schema;
//把XSD添加到xmlreaderSettings 的Schmas 模式中
settings.Schemas.Add(null,XmlReader.Create(xsdPath));//????????????这句有问题
reader = XmlReader.Create(xmlPath,settings);
while (reader.Read())
{
//
}
if (_builder.ToString() == String.Empty)
{
Response.Write("Validate complated successfully");
}
else
{
Response.Write("validate failed " + _builder.ToString());
} } public void ValidationEventHandler(object sender ,ValidationEventArgs args)
{
_builder.Append("error!" +args.Message +"</br>");
}
}
//
/-----------------other question attention------------
异常详细信息: System.NotSupportedException: 不支持给定路径的格式。源错误:
行 30: //------------------operate xmldoc data-----------------------------------
行 31: XmlDocument xmlDoc = new XmlDocument();
行 32: xmlDoc.Load(xmlFilePath);
行 33:
行 34: XmlElement authorElement = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("//authors/author/[au_id='172-32-1176']"); 源文件: c:\Inetpub\wwwroot\Chapter5\c.aspx.cs 行: 32
Program:
public partial class c : System.Web.UI.Page
{
private StringBuilder sb = new StringBuilder(); protected void Page_Load(object sender, EventArgs e)
{ XmlReader reader;
string xmlFilePath = Request.PhysicalApplicationPath + @"C:\Inetpub\wwwroot\Chapter5\author.xml";
string xsdFilePath = Request.PhysicalApplicationPath + @"C:\Inetpub\wwwroot\Chapter5\author.xsd";
//------------------operate xmldoc data-----------------------------------
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFilePath);//???????????????此句有问题呀。 XmlElement authorElement = (XmlElement)xmlDoc.DocumentElement.SelectSingleNode("//authors/author/[au_id='172-32-1176']");
authorElement.SetAttribute( "test" ,"test");
XmlNodeReader nodeReader = new XmlNodeReader(xmlDoc);//save xmldoc data //--------------------------validation xmldoc data---------------------------------------------
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationEventHandler += new ValidationEventHandler(this.ValidateEventHandler);//关联事件
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, XmlReader.Create(xsdFilePath));
reader = XmlReader.Create(nodeReader,settings);
while (reader.Read())
{
//
}
//-------------------judge string type---------------------
if (sb.ToString() == String.Empty)
{
Response.Write("validation is successful ");
}
else
{
Response.Write("validate failed " + sb.ToString() + "</br>");
}
}
public void ValidateEventHandler(object sender, ValidationEventArgs args)
{
sb.Append("eror!" + args.ToString() + "</br>");
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货