Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.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
试图将xml文件解析为C#aspx.net中的对象_C#_Asp.net_Xml - Fatal编程技术网

试图将xml文件解析为C#aspx.net中的对象

试图将xml文件解析为C#aspx.net中的对象,c#,asp.net,xml,C#,Asp.net,Xml,我在尝试将XML文件序列化为对象时遇到问题。 我让它在另一个项目中工作,但这次不起作用。 对象及其元素始终为空 我的XML文件: <ConferenceTextAttributes> <_lbl_TitleOfPage_Text>Registration</_lbl_TitleOfPage_Text> <_lbl_textBoxInfo_Text>(* mandatory fields)</_lbl_textBoxInfo_Tex

我在尝试将XML文件序列化为对象时遇到问题。 我让它在另一个项目中工作,但这次不起作用。 对象及其元素始终为空

我的XML文件:

  <ConferenceTextAttributes>
  <_lbl_TitleOfPage_Text>Registration</_lbl_TitleOfPage_Text>
  <_lbl_textBoxInfo_Text>(* mandatory fields)</_lbl_textBoxInfo_Text>
  <_lbl_mrsmr_Text>Mr/Ms:*</_lbl_mrsmr_Text>
  <_txt_mrsmr_Text></_txt_mrsmr_Text>
  <_lbl_title_Text>Title:</_lbl_title_Text>
  <_txt_title_Text></_txt_title_Text>
  <_lbl_firstname_Text>First Name:*</_lbl_firstname_Text>
  <_txt_firstname_Text></_txt_firstname_Text>
  <_lbl_surname_Text>Surname:*</_lbl_surname_Text>
  <_txt_surname_Text></_txt_surname_Text>
  <_lbl_institution_Text>Institution:*</_lbl_institution_Text>
  <_txt_institution_Text></_txt_institution_Text>
  <_lbl_department_Text>Department:*</_lbl_department_Text>
  <_txt_department_text></_txt_department_text>
  <_lbl_address_Text>Address:*</_lbl_address_Text>
  <_txt_address_text></_txt_address_text>
  <_lbl_zip_Text>Zip Code:*</_lbl_zip_Text>
  <_txt_zip_Text></_txt_zip_Text>
  <_lbl_city_Text>City:*</_lbl_city_Text>
  <_txt_city_Text></_txt_city_Text>
  <_lbl_country_Text>Country:*</_lbl_country_Text>
  <_txt_country_Text></_txt_country_Text>
  <_lbl_phone_Text>Phone:*</_lbl_phone_Text>
  <_txt_phone_Text></_txt_phone_Text>
  <_lbl_fax_Text>Fax:</_lbl_fax_Text>
  <_txt_fax_Text></_txt_fax_Text>
  <_lbl_email_Text>E-mail:*</_lbl_email_Text>
  <_txt_email_Text></_txt_email_Text>
  <_lbl_info_Text>I participate as a (former) mebmer of:</_lbl_info_Text>
  <_lbl_dropdown1_Text>If you are (former) member of NGFN-Plus / NGFN-Transfer please select</_lbl_dropdown1_Text>
  <_lbl_other_Text>other:</_lbl_other_Text>
  <_txt_other_Text></_txt_other_Text>
  <_lbl_chbInfo_Text>I will participate on these days:</_lbl_chbInfo_Text>
  <_chkb_day01_text>Montag</_chkb_day01_text>
  <_chkb_day02_text>Dienstag</_chkb_day02_text>
  <_chkb_day03_text>Mittwoch</_chkb_day03_text>
  <_chkb_day04_text>Donnerstag</_chkb_day04_text>
  <_chkb_day05_text>Freitag</_chkb_day05_text>
  <_chkb_day06_text>Samstag</_chkb_day06_text>
  <_chkb_day07_text>Sonntag</_chkb_day07_text>
  <_b_submit_Text>Register!</_b_submit_Text>
  <_b_cancle_Text>Cancel!</_b_cancle_Text>
  </ConferenceTextAttributes>
我要序列化的方法:

public ConferenceTextAttributes LeseMeistenTextAttribute(string sPfad2)
{
    XmlSerializer ser2 = new XmlSerializer(typeof(ConferenceTextAttributes));
    StreamReader sr2 = new StreamReader(sPfad2);
    ConferenceTextAttributes MyTextAttributes = 
        (ConferenceTextAttributes)ser2.Deserialize(sr2);
    sr2.Close();
    return MyTextAttributes;
}

xml中的字段名中有额外的下划线。在类中使用XmlElement属性来指定这些属性

[XmlElement("_lbl_msmr_text")]
public string lbl_msmr_text { get; set; }

标记名:
\u lbl\u titleof page\u Text
字段名:
lbl\u titleof page\u Text
找出差异。好的,我删除了所有下划线,现在可以了!谢谢我不明白的是,我在另一个项目中第一次这样做,xml文件中也有下划线,甚至类都是相同的。它的工作原理是。。。无论如何,我花了4小时找到你花了2秒钟,谢谢我的主人!!如果我明白你的意思,我就不是舒尔。你的意思是:?看这里:
[XmlElement("_lbl_msmr_text")]
public string lbl_msmr_text { get; set; }