2017-12-18 161 views
0

我有如下这个DTD此XML文件:http://www.edrdg.org/jmdict/jmdict_dtd_h.html反序列化XML文件XmlSerializer的,但一个属性包含其名称中的冒号

你可以看到,2个元素包含的属性在他们的名字一个冒号(:) :

L源和光泽可以包含命名xml:lang一个属性,因为在这个例子中看到(用于L源元素):

<entry> 
    <ent_seq>1002480</ent_seq> 
    <k_ele> 
     <keb>お転婆</keb> 
    </k_ele> 
    <k_ele> 
     <keb>御転婆</keb> 
    </k_ele> 
    <r_ele> 
     <reb>おてんば</reb> 
    </r_ele> 
    <sense> 
     <pos>&adj-na;</pos> 
     <pos>&n;</pos> 
     <misc>&uk;</misc> 
     <lsource xml:lang="dut">ontembaar</lsource> 
     <gloss>tomboy</gloss> 
    </sense> 
</entry> 

我不如何​​确保定义我的课代表lsource元素,在这里它是现在,但它缺少这个属性:

[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.7.2046.0")] 
    [System.SerializableAttribute()] 
    [System.Diagnostics.DebuggerStepThroughAttribute()] 
    [System.ComponentModel.DesignerCategoryAttribute("code")] 
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "JMdict_e.dtd")] 
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "JMdict_e.dtd", IsNullable = false)] 
    public partial class lsource 
    { 
     private string ls_typeField; 

     private string ls_waseiField; 

     private string valueField; 

     /// <remarks/> 
     [System.Xml.Serialization.XmlAttributeAttribute()] 
     public string ls_type 
     { 
      get 
      { 
       return this.ls_typeField; 
      } 
      set 
      { 
       this.ls_typeField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlAttributeAttribute()] 
     public string ls_wasei 
     { 
      get 
      { 
       return this.ls_waseiField; 
      } 
      set 
      { 
       this.ls_waseiField = value; 
      } 
     } 

     /// <remarks/> 
     [System.Xml.Serialization.XmlTextAttribute()] 
     public string Value 
     { 
      get 
      { 
       return this.valueField; 
      } 
      set 
      { 
       this.valueField = value; 
      } 
     } 
    } 

我应该如何命名属性XmlSerializer的正确识别和解析属性?我尝试添加属性public string xml_lang { get; set; }public string lang { get; set; }但都未能从XML文件解析属性时XmlSerializer.Deserialize被称为

回答

0

该属性是在未产生并为此元素/属性被忽略愉快命名空间。使用名称空间装饰lang属性将起作用:

[System.Xml.Serialization.XmlAttributeAttribute(Namespace = "http://www.w3.org/XML/1998/namespace")] 
public string lang { 
    get;set; 
} 

xml命名空间是W3C定义的标准命名空间。其值可以发现here

相关问题