How to extract a part of xml code from an xml file using c# code -


 <?xml version="1.0" encoding="utf-8" standalone="yes" ?>   <erecon xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:nonamespaceschemalocation="erecon.xsd">  <header>   <company code="" />    <commoncarriercode />    <inputfilename inputidpk="">f:\reconnew\tmesysrec20100111.rec</inputfilename>    <batchnumber>000152</batchnumber>    <inputstartdatetime>2010-02-26 11:47:00</inputstartdatetime>    <inputfinishdatetime>2010-02-26 11:47:05</inputfinishdatetime>    <recordcount>8</recordcount>    </header>  <detail>   <carrierstatusdate>2010-01-11</carrierstatusdate>    <claimnum>ydf02892 c</claimnum>    <invoicenum>0108013775</invoicenum>    <lineitemnum>001</lineitemnum>    <nabp>10600211</nabp>    <rxnumber>4695045</rxnumber>    <rxdate>2008-07-21</rxdate>    <checknum />    <paymentstatus>pending</paymentstatus>    <rejectdescription />    <invoicechargeamount>152.15</invoicechargeamount>    <invoicepaidamount>131.00</invoicepaidamount>   </detail>  </erecon> 

how can extract portion

 <header>   <company code="" />    <commoncarriercode />    <inputfilename inputidpk="">f:\reconnew\tmesysrec20100111.rec</inputfilename>    <batchnumber>000152</batchnumber>    <inputstartdatetime>2010-02-26 11:47:00</inputstartdatetime>    <inputfinishdatetime>2010-02-26 11:47:05</inputfinishdatetime>    <recordcount>8</recordcount>   </header> 

from above xml file.

i need c# code extract part of xml tag xml file.

if file isn't big (smaller few mb), can load xmldocument:

xmldocument doc = new xmldocument(); doc.load(@"c:\yourfile.xml"); 

and can parse <header> element using xpath expression:

xmlnode headernode = doc.selectsinglenode("/erecon/header"); if(headernode != null) {     string headernodexml = headernode.outerxml; } 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -