[英]Can't find “schemaLocation” attribute
I'm creating a schema to validate some XML, but when it comes down to actually reading in the document, I'm getting the error: 我正在创建一个模式来验证一些XML,但当它归结为实际阅读文档时,我收到错误:
The 'http://www.w3.org/2001/XMLSchema:schemaLocation' attribute is not declared.
This is what the beginning of one of the XML files using the schema looks like. 这就是使用模式的XML文件之一的开头。
<?xml version="1.0"?>
<envelope xsi:schemaLocation="C:\LocalPath MySchema.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema"
xmlns="http://tempuri.org/MySchema.xsd">
...
</envelope>
My validation code looks like this: 我的验证码如下所示:
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
Settings.Schemas.Add(@"http://tempuri.org/MySchema.xsd",
@"C:\LocalPath\ MySchema.xsd");
XmlReader reader = XmlReader.Create(@"C:\LocalPath\testxml\somefile.xml", settings);
xmlDoc.Load(reader);
ValidationEventHandler eventHander = new ValidationEventHandler(validationHandler);
xmlDoc.Validate(eventHander);
The namespace http://www.w3.org/2001/XMLSchema (with conventional prefix xsd
or xs
) is for schema documents; 命名空间http://www.w3.org/2001/XMLSchema (带有传统前缀xsd
或xs
)用于模式文档; the schemaLocation
attribute you want is in the namespace http://www.w3.org/2001/XMLSchema-instance (which has the conventional prefix xsi
for "XML Schema Instance namespace"). 您想要的schemaLocation
属性位于命名空间http://www.w3.org/2001/XMLSchema-instance (其中包含“XML Schema Instance namespace”的常规前缀xsi
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.