如何序列化c#对象来生成xml? [英] How to serialize c# object to generate xml?
本文介绍了如何序列化c#对象来生成xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写C#类,所以当我将它们序列化为XML时,它应该生成以下XML模式。
I want write C# classes, so that when I am serialize them in to XML, it should generate the following XML schema.
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:web="http://webservice.api.cabaret.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<soapenv:Header/>
<soapenv:Body>
<web:callArgs>
<name></name>
<args>
<entries>
<name>locator.content</name>
<value xsi:type="xs:string">AA==</value>
</entries>
<entries>
<name>locator.name</name>
<value xsi:type="xs:string">Reha0850.pdf</value>
</entries>
</args>
</web:callArgs>
</soapenv:Body>
</soapenv:Envelope>
请给我提供帮助,我应该如何编写c#类并将它们序列化以生成上述XML模式。
我尝试了什么:
我通过定义类并序列化它们尝试了很多,但我没有得到确切的架构我期待。
Please provide me the help, how should i write the c# classes and serialize them to generate above mentioned XML schema.
What I have tried:
I tried lot by defining the classes and serialize them, but I do not get the exact schema what I am expecting.
推荐答案
你有没看过 XmlSerializer类? XML架构定义工具(Xsd.exe)应该能够从您的架构中创建类在运行时序列化为文档。
Did you have a look into the XmlSerializer Class? XML Schema Definition Tool (Xsd.exe) should be able to create classes from your schema that are serialized into documents at runtime.
这篇关于如何序列化c#对象来生成xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文