从对象动态创建Xml

从对象动态创建Xml

本文介绍了从对象动态创建Xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个动态创建xml文件的场景,它应该是可序列化的,我的xml如下:

  <   person  >  
< personaldata >
< 名称 > gopi < / name >
< 姓氏 > ch < / lastname >
< / personaladat a >
< Educationaladata >
< 毕业 > b.tech < /毕业 >
< 指定 > 工程师< /名称 >
< / educationaldata >
< / person >





和我的c#代码如下

 public string CreateXmlObject(Person objPerson)
{
var objXmlDocument =新的XmlDocument();
var objXpath = objXmlDocument.CreateNavigator();
var objXmlSeialiser = new XmlSerializer(objPerson.GetType());
using(var xs = objXpath.AppendChild())
{
objXmlSeialiser.Serialize(xs,objPerson);
}
返回objXmlDocument.OuterXml;

}





但我的实际问题是我必须读取个人数据或educationdata等特定数据,当我更新文本框中的数据只需要更新必要的数据,就像个人数据一样





如何读取特定数据,例如personaldata

解决方案

Here I have a scenario that Create xml file dynamically and it should be serialisable and my xml is like following

<person>
<personaldata>
<name>gopi</name>
<lastname>ch</lastname>
</personaladata>
<Educationaladata>
<Graduation>b.tech</graduation>
<designation>Engineer</designation>
</educationaldata>
</person>



and my c# code is following

public string CreateXmlObject(Person objPerson)
        {
            var objXmlDocument = new XmlDocument();
            var objXpath = objXmlDocument.CreateNavigator();
            var objXmlSeialiser = new XmlSerializer(objPerson.GetType());
            using (var xs = objXpath.AppendChild())
            {
                objXmlSeialiser.Serialize(xs, objPerson);
            }
            return objXmlDocument.OuterXml;

        }



but my actual Problem is i have to read specifc data like personaldata or educationaldata and when i update data from text boxes only neccessary data should be updated like only personal data


How to read specific data like only personaldata

解决方案


这篇关于从对象动态创建Xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 00:10