本文介紹了XmlSerialization 和 xsi:SchemaLocation (xsd.exe)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我使用 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)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!