c# - Getting the root element of xml file in linq -


i using linq. here document structure:

<t totalword="2" creationdate="15.01.2016 02:33:37" ver="1">     <k kel_id="1000">         <kel>7</kel>         <kel_gs>0</kel_gs>         <kel_bs>0</kel_bs>         <km>ron/int-0014</km>         <kel_za>10.01.2016 02:28:05</kel_za>         <k_det kel_nit="12" kel_res="4" kelsid="1" >             <kel_ac>ac7</kel_ac>         </k_det>     </k>     <k kel_id="1001">         <kel>whitte down</kel>         <kel_gs>0</kel_gs>         <kel_bs>0</kel_bs>         <km>ron/int-0014</km>         <kel_za>15.01.2016 02:33:37</kel_za>         <k_det kel_nit="12" kel_res="4" kelsid="1">             <kel_ac>to gradually make smaller making taking parts away</kel_ac>             <kel_kc>cut down</kel_kc>             <kel_oc>the final key success turn interviewer champion: willing go bat when hiring committee meets whittle down list.</kel_oc>             <kel_trac >adım adım parçalamak</kel_trac>         </k_det>     </k> </t> 

this dictionary. t root. k word. when new word arrives, totalword attribute , creationdate shall update accordingly. have t node, attribute , save it. have written code above:

xdocument xdoc = xdocument.load(filename); xelement rootelement = xdoc.root; xelement koknode = rootelement.element("t"); xattribute toplamsayi = koknode.attribute("totalword"); 

koknode comes null. how can solve it? in advance.

xdoc.root return root element, t element in case.

rootelement.element("t") therefore return null t has no child t element.

either use xdoc.root or xdoc.element("t"), i.e.:

var tomplamsayi = xdoc.root.attribute("totalword") 

or:

var tomplamsayi = xdoc.element("t").attribute("totalword") 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -