c# - Why does my xmlCode return nothing -
i have xml code , want action's value:
<msg t='sys'><body action='rndk' r='-1'><k>randomkey</k></body></msg>
i've tried:
xmlcode.childnodes[0].attributes["action"]
which outputs nothing.
doing little homework, test code , find problem:
var = xelement.parse(@"<msg t='sys'><body action='rndk' r='-1'><k>randomkey</k></body></msg>"); var xmlnode = a.toxmldocument();
the above re-create xmlnode. toxmldocument
can found here.
then have following...
var msg = xmlnode.childnodes[0];
msg
first child node, if you'd separated out did, you'd see in debugger. rest follows naturally...
var body = msg.childnodes[0]; var action = body.attributes["action"]; string actionvalue = action.value;
the reason why code: xmlcode.childnodes[0].attributes["action"]
returns nothing msg
node doesn't contain action
attribute , therefore, nothing result.
Comments
Post a Comment