Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在XML中定义元素,而不创建不必要的类_C#_Xml_Xsd_Xsd.exe - Fatal编程技术网

C# 如何在XML中定义元素,而不创建不必要的类

C# 如何在XML中定义元素,而不创建不必要的类,c#,xml,xsd,xsd.exe,C#,Xml,Xsd,Xsd.exe,我希望用户将xml编写为: <Root> <Param> <Int>134</Int> </Param> </Root> <Root> <Param> <String>134</String> </Param> </Root> 这会产生这个好的代码 public partial clas

我希望用户将xml编写为:

<Root>
    <Param>
        <Int>134</Int>
    </Param>
</Root>
<Root>
    <Param>
        <String>134</String>
    </Param>
</Root>
这会产生这个好的代码

public partial class Root {
    public object Item { get; set; }
}
但是xml看起来像:

<Root>
    <Int>134</Int>
</Root>
它创建了一个不必要的类(RootParam),该类中只有一个对象。我想得到代码作为beofre

所以
我怎么做?如何在不创建愚蠢的伪不必要类的情况下强制XML中的元素<代码>var xe=新XElement(“根”,新XElement(“参数”,新XElement(“Int”,“134”));var xml=xe.ToString()Ok,但是为什么您首先在XML代码中有“愚蠢的伪不必要的”
param
元素?@Marcel:client的请求。在其他情况下,例如,作为序列或xs:short序列中的序列,xsd.exe查看
123412341234
并生成
short[][]表
,并且不为行或表创建新类。我需要把文件读到课堂上。这些类又绑定到WPF控件,并具有其他功能。
<Root>
    <Int>134</Int>
</Root>
<?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>
public partial class Root {
    public RootParam Param { get; set; }
}

public partial class RootParam {
    public object Item { get; set; }
}