c# - Most efficient way to read two nodes from multiple XML files? -
i'm looking fast , efficient way retreive 2 strings multiple xml files.
the files them selves aren't big 50kb 100kb , number of files can range none 100. i've included sample of small xml file i'll using. xml files same format , there's 2 things need know files namely:
<company>test bv.</company> <ship>sss testing</ship> i want store these strings in struct/class since cannot use tuple in .net 3.5 (or mistaking?)
so question: efficient way this? using xdocument? using xmlreader? or else?
<?xml version="1.0" encoding="utf-8"?> <collection xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <customer> <id>-1</id> <updated>true</updated> <company>test bv.</company> <ship>sss testing</ship> <adress>fggfgggff gvg</adress> <city>fgcgg</city> <zipcode>5454fc</zipcode> <country>fcgggff</country> <btw_nmbr>55</btw_nmbr> <istempcustomer>true</istempcustomer> <phonenumbers> <contactdata> <id>21</id> <updated>true</updated> <description>455656567</description> <name>ghbbvh</name> <issendable>false</issendable> </contactdata> <contactdata> <id>22</id> <updated>true</updated> <description>2315098234146124302134</description> <name>asdfawegaebf</name> <issendable>false</issendable> </contactdata> </phonenumbers> <emailadresses /> </customer> <order> <id>-1</id> <updated>true</updated> <ordernr>10330200</ordernr> <orderdate>1-1-2005</orderdate> <startdate>10-9-2013</startdate> <expirationdate>20-10-2013</expirationdate> <executor>andre de zwart</executor> <executors /> <reference /> <orderdetail /> <isdigital>true</isdigital> </order> <materials> <materialdata> <id>108</id> <updated>true</updated> <description>ffdffggfg</description> <amount>34</amount> </materialdata> <materialdata> <id>109</id> <updated>true</updated> <description>ffccff</description> <amount>45</amount> </materialdata> </materials> <hourexpenses> <hourexpensesdata> <id>43850</id> <updated>true</updated> <date>2013-10-06t00:00:00</date> <notes>lala</notes> <day>sunday</day> <hours>0.01</hours> <businesshours>0.01</businesshours> <travledhoursto>0</travledhoursto> <travledhoursfrom>0</travledhoursfrom> <start>2013-10-06t12:27:00</start> <stop>2013-10-06t12:27:00</stop> </hourexpensesdata> <hourexpensesdata> <id>43849</id> <updated>true</updated> <date>2013-09-17t00:00:00</date> <notes>oke dus ik ben nu lekker aan het werk en ik typ wat spul er bij</notes> <day>tuesday</day> <hours>0</hours> <businesshours>0.01</businesshours> <travledhoursto>0</travledhoursto> <travledhoursfrom>0</travledhoursfrom> <start>2013-09-17t12:31:31</start> <stop>2013-09-17t12:31:32</stop> </hourexpensesdata> <hourexpensesdata> <id>43855</id> <updated>true</updated> <date>2013-10-03t00:00:00</date> <notes>test</notes> <day>thursday</day> <hours>0</hours> <businesshours>0</businesshours> <travledhoursto>12</travledhoursto> <travledhoursfrom>12</travledhoursfrom> <start>0001-01-01t00:00:00</start> <stop>0001-01-01t00:00:00</stop> </hourexpensesdata> </hourexpenses> <travelexpenses> <travelexpensesdata> <id>672</id> <updated>true</updated> <date>2013-09-27t00:00:00</date> <notes /> <kmto>45</kmto> <kmfrom>45</kmfrom> <declaration>0</declaration> </travelexpensesdata> </travelexpenses> <signatures> <id>-1</id> <updated>true</updated> <orderid>10330200</orderid> <completed>false</completed> <notes>yay het werkt ;d</notes> </signatures> <removeddatalist /> </collection>
i use linq xml in simplest possible way:
var query = file in files let doc = xdocument.load(file) customer in doc.descendants("customer") select new { company = (string) customer.element("company"), ship = (string) customer.element("ship") }; i'd expect pretty quick - should work out exact performance requirements are, test them. (you don't need "the efficient" way - need sufficiently efficient way, whilst keeping code readable.)
note if want values propagated out of current method, should create own class represent company/ship pair.
Comments
Post a Comment