all groups > dotnet xml > november 2004 >
You're in the

dotnet xml

group:

Can XML do this?


Can XML do this? Just Me
11/24/2004 4:45:11 PM
dotnet xml: I know nothing about XML and am asking this so I know if I should spend some
time learning.

I had a VB6 address book app that I converted to .net
It reads and writes records in a random file.
That is, each record is the same size, (composed of items that are fixed
size strings.)
If no middle name item, for example, is entered blanks are written for that
item.
Using a random file lets me read, for example, the 10th record if I want to,
without reading records 1 thru 9.

I converted to .NET and the conversion created things that enable the code
to appear as if it had fixed size strings, but it's kind of kluggy.

I wonder if XML wouldn't work well.

To restate the question:
An address book application.
Many of the possible items for a given contact might not be filled in.
Most items are not as long as the max allowable length.
They are padded with blanks.
If the entries(contacts) were written including only the nonblank unpadded
items.
Could I read and rewrite the entries in a random order.

I'd guess the answer is no.
In that case, If the written entries were all the same size because blanks
would be used to pad items so they become fixed size.

Would it make sense to use XNL?


Thanks for any helpful suggestions

P.S. Is there XML address book example code available on the Internet?

Re: Can XML do this? Oleg Tkachenko [MVP]
11/25/2004 7:27:27 PM
[quoted text, click to view]

Yeah, XML is basically bad on effective random read/write access unless
you load the whole document into memory. Basically you can have each
record on separate line and fixed length of data, but that sounds as
really weird XML file.


--
Oleg Tkachenko [XML MVP]
Re: Can XML do this? Just Me
11/26/2004 9:49:32 AM

[quoted text, click to view]

If it must be fixed length I might as well stay with the simpler approach.

I suppose I could use variable length strings for the items ( a contact
might has about 20 optional items) and before I write to a random file,
combine them into one string padded to a certain length, rather than padding
each item.


It seems surprising to me that dotnet has no built-in provisions for random
files of strings.



Thanks for the insight



Re: Can XML do this? schneider
12/15/2004 5:00:06 PM
You could use Binary writer to do this. This is like a .DBF file.
I wrote a class to write .DBF files once which is similar approach.

There are also methods on string for padding (PadLeft, PadRight) to simulate
fixed lenght fields.

You might also look for a Radom Acess library, I think I saw some code
http://www.codeproject.com/vb/net/ybrandomfile.asp not sure how well it
works.

Schneider


[quoted text, click to view]

AddThis Social Bookmark Button