[英]c# class to xml attribute name with numbers
I am trying to XmlSerializer a class in c#. 我试图XmlSerializer在C#中的一个类。
When my XML tags are 当我的XML标签是
<Identificadores>
<IdMensaje>123</IdMensaje>
<IdMensajeAnterior >123</IdMensajeAnterior>
<IdOperacion >123</IdOperacion>
Is simple, having a Indentificadores class name al properties with tag 很简单,使用一个带有标签的Indentificadores类名称al属性
[XmlRoot(ElementName = "Identificadores")]
public partial class Indetifiers
{
[XmlElement(ElementName = IdMensaje")]
public string AAA{ get; set; }
[XmlElement(ElementName = IdMensajeAnterior")]
public string BBB{ get; set; }
[XmlElement(ElementName = IdOperacion")]
public string CCC{ get; set; }
}
The problem I have is when XML tags has simbols or numbers... 我的问题是XML标签包含符号或数字时...
<_01:Identificadores>
<_01:IdMensaje>123</_01:IdMensaje>
<_01:IdMensajeAnterior >123</_01:IdMensajeAnterior>
<_01:IdOperacion >123</_01:IdOperacion>
</_01:Identificadores>
I can not use ElementName with prefix _01:
我不能使用带有前缀
_01:
ElementName _01:
There was an error reflecting type Identificadores
反映
Identificadores
类型的错误
I have XML serialize
error 我有
XML serialize
错误
Is there a way to use nomber and symbols to create those tags from a class? 有没有一种方法可以使用Nomber和符号从类中创建这些标签?
Thanks 谢谢
Please have a look at this: https://msdn.microsoft.com/en-us/library/aa468565.aspx 请看一下: https : //msdn.microsoft.com/en-us/library/aa468565.aspx
The numbers you're referring to in your example are actually namespace aliases. 您在示例中引用的数字实际上是名称空间别名。 So when you define your serialization/deserialization attributes you need to specify the namespaces prefixes in order to avoid XML serialization errors.
因此,在定义序列化/反序列化属性时,需要指定名称空间前缀,以避免XML序列化错误。
As I mentioned, please have a look at the link above to understand better how XML namespaces work. 正如我提到的,请查看上面的链接以更好地了解XML名称空间的工作方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.