.net - XML parsing using C# for sibling element with namespace -


i've complex xml , parse in c# using linq:

<?xml version="1.0"?> <?mso-application progid="word.document"?> <w:worddocument xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml" xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxhint" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:dt="uuid:c2f41010-65b3-11d1-a29f-00aa00c14882" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xml:space="preserve" w:embeddedobjpresent="no"> <w:docpr xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">     <w:displaybackgroundshape/>     <w:view w:val="print"/>     <w:zoom w:percent=""/>     <w:defaulttabstop w:val="708.1365"/>     <w:docvars/> </w:docpr> <w:body>     <w:p xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0">     <w:ppr>     <w:pstyle w:val="author_28_s_29_"/>     </w:ppr>     <w:r>     <w:rpr><w:rstyle w:val="t4"/></w:rpr>     <w:t>satyam</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t5"/>     </w:rpr>     <w:t>singh</w:t>     </w:r>     <w:r>     <w:t>,</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t6"/>     </w:rpr>     <w:t>disha</w:t>     </w:r>     <w:r>     <w:t>a</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t4"/>     </w:rpr>     <w:t>.</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t5"/>     </w:rpr>     <w:t>shah</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t7"/>     </w:rpr>     <w:t>,2,*</w:t>     </w:r>     <w:r>     <w:t>,</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t4"/>     </w:rpr>     <w:t>karan</w:t>     </w:r>     <w:r>     <w:rpr>     <w:rstyle w:val="t5"/>     </w:rpr>     <w:t>bhutwala</w:t>     </w:r>    </w:p> </w:body> </w:worddocument> 

so as:

author_28_s_29_=satyam singh

author_28_s_29_=disha shah

author_28_s_29_=karan bhutwala

.

.

so on.

i've tried couple of options parse. logic here can taken

parent().children.where(r).(t).value

this xml strange. perhaps there easier way, got this:

 xdocument xd = xdocument.load("1.xml"); xnamespace nms = "http://schemas.microsoft.com/office/word/2003/wordml";      var author = xd.root.element(nms + "body")                 .descendants(nms + "pstyle")                 .single()                 .attribute(nms + "val").value;      var arr = string.join(" ", xd.root.element(nms + "body")                 .descendants(nms + "t").select(y => y.value))                 .split(',').where(y => y.length > 2)                 .select(y => string.format("{0}={1}", author, y.trim()))                 .toarray();      foreach (var x in arr)         console.writeline(x); 

out:

author_28_s_29_=satyam singh author_28_s_29_=disha . shah author_28_s_29_=karan bhutwala 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -