本文介绍了访问XSD文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问这样的模式文件:

Dim settings As XmlReaderSettings = New

XmlReaderSettings()

settings.Schemas.Add(webServiceNamespace,schemaFileName)

settings.ValidationType = ValidationType.Schema


即使上面的webServiceNamespace值设置为内联网

地址,我一直收到这个错误:


找不到文件''C:\Program Files \ Microsoft Visual Studio

8 \ Common7 \IDE \XmlCommand.xsd


为什么在那里寻找XSD文件?有没有办法让它

查看我放入代码的实际位置?

解决方案



Add方法的第二个参数是位置。第一个

参数只是名称空间URI,它不是一个位置。所以传递

作为第二个参数的位置。对于第一个参数,您可以在Nothing中传递

,这样XML解析器就会使用

架构中定义的命名空间。


-


Martin Honnen --- MVP XML





加载XML时需要使用上述设置,例如而不是

LoadXml使用

xmlDoc.Load(XmlReader.Create(New StringReader(xmlCommandString),

设置))


或者作为替代方法,如果您只想在加载

XML后进行验证,则需要创建一个XmlSchemaSet并将xmlDoc.Schemas设置为

XmlSchemaSet,在将模式添加到模式集之后。


-


Martin Honnen --- MVP XML


I''m trying to access a schema file as such:

Dim settings As XmlReaderSettings = New
XmlReaderSettings()
settings.Schemas.Add(webServiceNamespace, schemaFileName)
settings.ValidationType = ValidationType.Schema

Even though the webServiceNamespace value above is set to an intranet
address, I keep getting this error:

Could not find file ''C:\Program Files\Microsoft Visual Studio
8\Common7\IDE\XmlCommand.xsd

Why is it looking for the XSD file there? Is there a way to have it
look in the actual spot I put in my code?

解决方案

The second argument to the Add method is the location. The first
argument is simply the namespace URI which is not a location. So pass in
the location as the second argument. For the first argument you can pass
in Nothing, that way the XML parser uses the namespace defined in the
schema.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/



You need to use the above settings when loading the XML e.g. instead of
LoadXml use
xmlDoc.Load(XmlReader.Create(New StringReader(xmlCommandString),
settings))

Or as an alternative way, if you only want to validate after loading the
XML, you need to create an XmlSchemaSet and set xmlDoc.Schemas to that
XmlSchemaSet, after you have added your schema(s) to the schema set.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


这篇关于访问XSD文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 08:08