简体   繁体   中英

Change ElementName from generate xsd class

Using the xsd.exe tool, class are generate from a xsd file. I would like to change the name of a root element put I can not since the XmlRootElementAttribute can not be duplicate. So idealy I would like that the xsd tool generate a partial classe like this:

...
[System.Xml.Serialization.XmlRootAttribute(ElementName="Request", IsNullable=false)]
public partial class SendMessage  { ... }

But I have no clue how to change the ElementName propertie.

Thanks

I take your XSD defines an element SendMessage , and you want the annotation to be something else, Request in your case.

Short answer is no, it cannot be done with XSD.exe alone; the tool doesn't allow a syntax where one can customize the name of the generated classes.

Which brings in the long version of the answer... The annotations always reflect what the XML is. If you change the ElementName value, then your generated XML will be different. If you want the XML different, then you should change the schema file instead.

This is the kind of question that needs a lot of explaining as to why would one want this... in order to get a positive answer, as in "yes, this is how achieve the why ".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM