I'm using C# to make an app for the Pocket PC (funny enough) and was wondering when using xmldocument.load , how I can get the number of bytes loaded
A 300kb XML file can take a few seconds on the pocket pc so I wanted some way of getting the bytes loaded to make a progress bar. I was thinking of timing the first time the xml file was loaded and then storing this and using it as an estimate (I can see the problems with this) but surely there must be a better way
I'm pretty new to C# so please be simple with your reply :) .
Thanks for any help you can provide,
Jon.
Note: I got a feeling this isn't probably .net compact only
/me hides
EDIT: Just incase it helps, this is a sample of the XML I've got to read in (not created by me)
< xml version="1.0" standalone="yes" >
<diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<Contacts xmlns="http://tempuri.org/Contacts.xsd">
<bb_Contact diffgr:id="bb_Contact1" msdata:rowOrder="0">
<ContactID>e7jud45d-cb3e-4ed5-942c-0247a4987d49</ContactID>
<OwnerID>118</OwnerID>
<CountryID>826</CountryID>
<Title>1</Title>
<Forename>foreame was here</Forename>
<Surname/>
<EmailAddress/>
<AddressLine1/>
<AddressLine2/>
<AddressLine3/>
<Town/>
<County/>
<PostalCode/>
<Telephone1/>
<Telephone2/>
<Fax/>
<BillTitle>0</BillTitle>
<BillForename/>
<BillSurname/>
<BillEmailAddress/>
<BillAddressLine1/>
<BillAddressLine2/>
<BillAddressLine3/>
<BillTown/>
<BillCounty/>
<BillPostalCode/>
<BillCountryID>0</BillCountryID>
<BillTelephone1/>
<BillTelephone2/>
<BillFax/>
<HasBillingAddress>false</HasBillingAddress>
<Referral/>
</bb_Contact>
<bb_Contact diffgr:id="bb_Contact2" msdata:rowOrder="1">
<ContactID>bjju04e-85da-4aea-8125-0260dcb96241</ContactID>
<OwnerID>118</OwnerID>
<CountryID>826</CountryID>
<Title>1</Title>
<Forename>forename here blah blah</Forename>
<Surname>surname here blah blah</Surname>
<EmailAddress/>
<AddressLine1>add1 </AddressLine1>
<AddressLine2/>
<AddressLine3>add3</AddressLine3>
<Town/>
<County/>
<PostalCode>postcode here</PostalCode>
<Telephone1>1231443554345345</Telephone1>
<Telephone2/>
<Fax/>
<BillTitle>0</BillTitle>
<BillForename/>
<BillSurname/>
<BillEmailAddress/>
<BillAddressLine1/>
<BillAddressLine2/>
<BillAddressLine3/>
<BillTown/>
<BillCounty/>
<BillPostalCode/>
<BillCountryID>0</BillCountryID>
<BillTelephone1/>
<BillTelephone2/>
<BillFax/>
<HasBillingAddress>false</HasBillingAddress>
<Referral/>
</bb_Contact>
Etc...
And the code I'm using is:
XmlNodeList
forenames = xDoc.GetElementsByTagName("Forename"); XmlNodeList surnames = xDoc.GetElementsByTagName("Surname");Which I'm then joining together using the same index position, not the best way

[SOLVED] xmldocument.load - Anyway to get bytes loaded?
Rudra Poudel
RIGHT. Guess I'll have to learn by my own mistakes. I think that it would be nice to have some idea how much of the file is loaded. I'm gonna go down that path and see how it turns out. As for the XML and the prog that made it, I can't use any of the code as its not mine and I can guarantee they won't let me use it.
I'll let you know how I get on.
Thanks all for your help and suggestions.
Yami_Rafa
Hey thanks for the reply.
Like I said though I've only just started learning C# and also never used XML before. I've seen something about datasets so I'll read up more.
Still though, how can I get the current size of the file loaded so that I can work out the %age loaded
Thanks,
Jon.
BillAPgh
K enough editing my first post.
Been reading through various stuff and it seems I should be using XmlTextReader. Why I think this:
http://msdn.microsoft.com/library/default.asp url=/library/en-us/dnpag/html/ScaleNetChapt09.asp
because it says its used for streaming which means I should be able to get byte size at point n. So for example:
XmlTextReader xDocReader = new XmlTextReader ("contacts.xml");
while (XDocReader.Read()){
// get a node at a time
// get its length
// work out it overall % loaded from total of all loaded loads
}
think this is on the right track anyway O_o .
Kevin Tough
This XML is a diffgram which represents serialized DataSet. Why are you loading it into DOM instead of restoring it into DataSet
24sharon
You can extend file stream class to do that, but it's probably not worth it. Just move progress bar using timer to show your application is doing something. Considering loading time can fluctuate a lot based on file content and CPU load it’s just as informative as actual percentage.
As to DataSet, you should consult whoever provided you with this XML file. You might be able to reuse code from desktop.