我使用 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!