c# - how to get values from xml response -


how address , netmask values following xml response

<?xml version="1.0" encoding="utf-8" ?>      - <controls>       <manualcalib>0</manualcalib>        <maintmode>0</maintmode>        <antenable>0</antenable>        <chgbeamenable>1</chgbeamenable>        <modemresponse>options show eth0_1 [eth0_1] address = 10.171.74.1 netmask = 255.255.255.0 rip_enabled = 0 [rmt:416] admin@telnet:::ffff:127.0.0.1;4709 ></modemresponse>        </controls> 

the best solution find out exact structure of modemresponse string. write regular expression capture values need, or have more robust parsing logic. if don't know exact structure, write hacky code done in cases:

        var xd = xdocument.parse(xml);         var modemresponse = xd.element("controls").element("modemresponse").value;         string address = string.empty, netmask = string.empty;         var tokens = modemresponse.split(new[] { ' ', '=' }, stringsplitoptions.removeemptyentries);         (int = 0; < tokens.length; i++)         {             var token = tokens[i];             switch (token)             {                 case "address":                     if (i + 1 < token.length)                         address = tokens[i + 1];                     break;                 case "netmask":                     if (i+1 < tokens.length)                         netmask = tokens[i+1];                     break;             }         }          console.writeline("address: {0}, netmask: {1}", address, netmask); 

Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -