c# - How to define element in the XML, without creating unnessecery class -


i want users write xml one:

<root>     <param>         <int>134</int>     </param> </root> 

or one:

<root>     <param>         <string>134</string>     </param> </root> 

and, want auto-generated c# code of xsd (i use xsd.exe) not generate new class param, use object.

first try

now, when write xsd, i've started markup:

<?xml version="1.0" encoding="utf-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="root">         <xs:complextype>             <xs:sequence>                 <xs:choice>                     <xs:element name="int" type="xs:int"/>                     <xs:element name="string" type="xs:string"/>                 </xs:choice>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

which yield good code

public partial class root {     public object item { get; set; } } 

but xml like:

<root>     <int>134</int> </root> 

which bad purposes.

second try

so, i've tried fix xsd, , have now:

<?xml version="1.0" encoding="utf-8" ?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema">     <xs:element name="root">         <xs:complextype>             <xs:sequence>                 <xs:element name="param">                     <xs:complextype>                         <xs:choice>                             <xs:element name="int" type="xs:int"/>                             <xs:element name="string" type="xs:string"/>                         </xs:choice>                     </xs:complextype>                 </xs:element>             </xs:sequence>         </xs:complextype>     </xs:element> </xs:schema> 

now, xml want (with "param" element), but code ugly:

public partial class root {     public rootparam param { get; set; } }  public partial class rootparam {     public object item { get; set; } } 

it creats unnessecery class (rootparam) has in object. code beofre.

so...

how can it? how force element in xml, without creating stupid fake unnessecery class?


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -