XML 架构定义工具不生成 SchemaLocation

发布于 2024-07-23 10:44:59 字数 253 浏览 4 评论 0原文

从普通的旧 C# 对象生成 XSD 时,Visual Studio 提供的 xsd.exe 工具是否会生成 SchemaLocation 属性(在 xs:import 中)?

我发现生成的 XSD 无效,因为 xs:import 将导入命名空间并且不提供相对 schemalocation 值,提示以下内容

命名空间“urn:company-event-namespace”的导入架构未解析。

Does the xsd.exe tool provided with Visual Studio generate the SchemaLocation attribute (in the xs:import) when generating XSDs from plain old C# objects?

I am finding that my XSDs that were generated are not valid because the xs:import will import a namespace and not provide the relative schemalocation value prompting the below

Imported Schema for namespace 'urn:company-event-namespace' was not resolved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

筱武穆 2024-07-30 10:44:59

此答案所示,您可以手动添加属性。
由于 xsd 工具生成分部类,因此您可以在单独的文件中添加此属性,因此不必修改生成的文件。

public partial class Gpx
{
    [XmlAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
    public string xsiSchemaLocation = "http://www.topografix.com/GPX/1/1 " +
                                 "http://www.topografix.com/GPX/1/1/gpx.xsd";
}

As shown in this anwser you can add manually add an attribute.
Because the xsd tool generates a partial class, you can add this attribute in a seperate file, so you don't have to modify a generated file.

public partial class Gpx
{
    [XmlAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
    public string xsiSchemaLocation = "http://www.topografix.com/GPX/1/1 " +
                                 "http://www.topografix.com/GPX/1/1/gpx.xsd";
}
A君 2024-07-30 10:44:59

正如您所发现的,它不会生成该属性。 这可能与以下事实有关:如果该属性存在于它正在读取的模式中,则它不会使用该属性。

As you've found, it does not generate that attribute. This may have to do with the fact that it would not use that attribute if the attribute were present in a schema it was reading.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文