C# 如何更改XML父标记

C# 如何更改XML父标记,c#,xml,winforms,C#,Xml,Winforms,假设我有这样一个xml文件: <ArrayOfInternetProxy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <InternetProxy> <ProxyName /> <ProxyIP>23.19.34.127:8800</ProxyIP> &l

假设我有这样一个xml文件:

<ArrayOfInternetProxy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <InternetProxy>
    <ProxyName />
    <ProxyIP>23.19.34.127:8800</ProxyIP>
    <Username />
    <Password />
  </InternetProxy>
</ArrayOfInternetProxy>
但这对其他标签不起作用

谢谢

我的班级:

public class InternetProxy //I want to change this in the xml output
{
    [XmlElement("ProxyName")]
    public string ProxyName { get; set; }

    [XmlElement("ProxyIP")]
    public string Address { get; set; }

    [XmlElement("Username")]
    public string UserName { get; set; }

    [XmlElement("Password")]
    public string Password { get; set; }
}
编辑:

这是我试过的,为什么这对我不起作用

[XmlElement("Proxies")]
[XmlArray("Proxies")]
List<InternetProxy> proxies;
[XmlElement(“代理”)]
[XmlArray(“代理”)]
列出代理人名单;

您应该有如下内容:

[XmlArray("Proxies")]
public InternetProxy[] InternetProxy
{
   get;
   set;
}
要控制其序列化方式,可以应用以下属性:

  • XmlArrayAttribute
    :它将更改数组的名称(实际的
    ArrayFinternetProxy
  • XmlArrayItemAttribute
    :它将更改数组项的名称(实际的
    InternetProxy
如果直接序列化数组(因此数组中没有此类属性),则应应用XmlType属性,如:

[XmlType(TypeName="Proxies")]
public class InternetProxy
{
}

有关详细信息,请参阅。

您可以提供您的类和所需的输出吗?这是否仍然适用于列表?我尝试了标签,但它仍然使用默认名称。我修复了它。问题是,如果数组是父节点(最外面的数组),则不能以这种方式更改节点名称。
[XmlType(TypeName="Proxies")]
public class InternetProxy
{
}