2017-12-18 136 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

相關問題