简体   繁体   中英

how do I serialize a xml node in c#

I have a xml node.

      <Region Region_Sequence="1" Region_Name="Vadodra" Region_Code="VAD"/>

how can I serialize this xmlnode to my region class using c# and asp.net

You can do the following:

using System.Xml.Linq;

namespace XMLParser
{
    class ParseXML
    {
     public void ParseXML(string strXML)
{
XDocument xdoc = XDocument.Load(strXML);
var region= from regions in xdoc.Element("Region");

Region objRegion=new Region();
Region.Region_Name=region.Element("Region_Name").Value.ToString();
}
}

}

Something like this:

string xml = "<Region Region_Sequence=\"1\" Region_Name=\"Vadodra\" Region_Code=\"VAD\"/>"

var serializer = new XmlSerializer(typeof(Region));
Region result;

using (TextReader reader = new StringReader(xml))
{
    result = (Region)serializer.Deserialize(reader);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM