XmlSerialization 和 xsi:SchemaLocation (xsd.exe) [英] XmlSerialization and xsi:SchemaLocation (xsd.exe)

查看:25
本文介绍了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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆