XmlSerialization和xsi:SchemaLocation(xsd.exe) [英] 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
属性。
这篇关于XmlSerialization和xsi:SchemaLocation(xsd.exe)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文