我想将 xml 文件中的字符串转换为 ContactPersonType
请参阅 for 循环以了解需要转换字符串的位置
public class ContactPersonType
{
private String _id;
public String ID
{
get { return _id; }
set { _id = value; }
}
private String _name;
public String Name
{
get { return _name; }
set { _name = value; }
}
}
//联系人类
private ContactPersonType _jobRole;
public ContactPersonType JobRole
{
get { return _jobRole; }
set { _jobRole = value; }
}
public static ObservableCollection<ContactPerson> getContactPerson()
{
ObservableCollection<ContactPerson> ContactPersons = new ObservableCollection<ContactPerson>();
XmlDocument doc = new XmlDocument();
doc.Load("contactpersoon.xml");
XmlNodeList elemList = doc.GetElementsByTagName("contact");
for (int i = 0; i < elemList.Count; i++)
{
//this needs to be casted to ContactPersonType
contactPerson.JobRole = elemList[i]["jobrole"].InnerText;
}
return ContactPersons;
}