XmlSerialization and xsi:SchemaLocation (xsd.exe)(XmlSerialization 和 xsi:SchemaLocation (xsd.exe))
问题描述
我使用 xsd.exe 生成了一个用于读取/写入 GPX 文件的 C# 类.如何让生成的 XML 文件包含 xsi:schemaLocation 属性例如.
I used xsd.exe to generate a C# class for reading/writing GPX files. How do I get the resultant XML file to include the xsi:schemaLocation attribute eg.
我想要以下但 xsi:schemaLocation 总是丢失
I want the following but xsi:schemaLocation is always missing
<?xml version="1.0"?>
<gpx
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
version="1.1"
xmlns="http://www.topografix.com/GPX/1/1"
creator="ExpertGPS 1.1 - http://www.topografix.com"
xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
</gpx>
推荐答案
将此添加到您生成的 C# 类中:
Add this to your generated C# class:
[XmlAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
public string xsiSchemaLocation = "http://www.topografix.com/GPX/1/1 " +
"http://www.topografix.com/GPX/1/1/gpx.xsd";
显然 xsd.exe
工具 不会生成 schemaLocation
属性.
Apparently the xsd.exe
tool does not generate the schemaLocation
attribute.
这篇关于XmlSerialization 和 xsi:SchemaLocation (xsd.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:XmlSerialization 和 xsi:SchemaLocation (xsd.exe)


基础教程推荐
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01