XmlSchemaSet.Add()方法接受一个Uri和目标命名空间,但是当我试图传入一个本地文件位置时,它会产生一个错误。
_schemaUri = @"L:\schemaDoc.xsd";
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(_schemaUri, _targetNamespace);错误:
NotSupportedException was caught
The URI prefix is not recognized.发布于 2014-04-08 16:53:21
是。您已经混淆了Add方法的参数。第一个参数是目标命名空间,第二个参数是URI。所以您的代码应该如下所示:
_schemaUri = @"L:\schemaDoc.xsd";
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add(_targetNamespace, _schemaUri);有关更多细节,请参阅文档:
http://msdn.microsoft.com/en-us/library/1hh8b082%28v=vs.110%29.aspx
发布于 2014-04-08 16:53:30
根据MSDN文档,schemaUri和targetNamespace参数的顺序相反。
来自MSDN:
XmlSchemaSet.Add Method (String, String)在XmlSchemaSet指定的URL上添加XmlSchemaSet定义语言(XSD)架构。
Namespace: System.Xml.Schema
Assembly: System.Xml (in System.Xml.dll)
public XmlSchema Add(
string targetNamespace,
string schemaUri
)参数
targetNamespace
Type: System.String
The schema targetNamespace property, or null to use the targetNamespace specified in the schema.
schemaUri
Type: System.String
The URL that specifies the schema to load. http://msdn.microsoft.com/en-us/library/1hh8b082(v=vs.110).aspx
https://stackoverflow.com/questions/22942480
复制相似问题