xmlNode to objects

前端 未结 3 1724
借酒劲吻你
借酒劲吻你 2021-02-05 18:14

I have been working with a 3rd party java based REST webservice, that returns an array of xmlNodes.

The xmlNode[] respresent an object and I am trying to work out the b

3条回答
  •  孤街浪徒
    2021-02-05 19:11

    Maybe this is too late to answer here but it will help others:

    Here is the solution you will be able to Deserialize from the XML node.

     XmlDocument xmlDoc = new XmlDocument();
     xmlDoc.LoadXml(xml);
    
     XmlNode xmlNode = xmlDoc.SelectSingleNode("//SystemInfo");
    
     XmlSerializer serial = new XmlSerializer(typeof(SystemInfo));
    
     SystemInfo syso =(SystemInfo)serial.Deserialize(new XmlNodeReader(xmlNode));
    

    The first load the XML to XmlDocument Object and then find the parent node you will wish to deserialize just like I want SystemInfo object node from all the XML document.

    Once you find that create an XmlSerializer object with the specific class type you will wish to.

    Now just pass the new XmlNodeReader(xmlNode) to the Deserialize method, you will get the objects populated in the class object just like I populated syso object with XML values.

    Happy Coding :)

提交回复
热议问题