XML Schema Definition Tool not generating SchemaLocation

℡╲_俬逩灬. 提交于 2019-12-11 01:52:26

问题


Does the xsd.exe tool provided with Visual Studio generate the SchemaLocation attribute (in the xs:import) when generating XSDs from plain old C# objects?

I am finding that my XSDs that were generated are not valid because the xs:import will import a namespace and not provide the relative schemalocation value prompting the below

Imported Schema for namespace 'urn:company-event-namespace' was not resolved.


回答1:


As you've found, it does not generate that attribute. This may have to do with the fact that it would not use that attribute if the attribute were present in a schema it was reading.




回答2:


As shown in this anwser you can add manually add an attribute. Because the xsd tool generates a partial class, you can add this attribute in a seperate file, so you don't have to modify a generated file.

public partial class Gpx
{
    [XmlAttribute("schemaLocation", Namespace = XmlSchema.InstanceNamespace)]
    public string xsiSchemaLocation = "http://www.topografix.com/GPX/1/1 " +
                                 "http://www.topografix.com/GPX/1/1/gpx.xsd";
}


来源:https://stackoverflow.com/questions/955958/xml-schema-definition-tool-not-generating-schemalocation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!