tags:

views:

176

answers:

8

I am parsing the html file to extract tabular information through column names. And I want like let user give the input for column name. And according to that column names tabular information will be extracted.

Now that column names which user will input,based on that column names I want to find the tabular information from the html file.

But where I should store this column names input by user ? And how to retrieve them ? I dont want to use database.

EDIT : How can we store data in xml file and how can we retrieve data from it and how can we update the xml file for storing data ? Like I have 3 column names Name, Address,Phone no and for that user will input possible column names like Nm,Add,PhNo. and Nam,Addre,PhoNo and so on.

+3  A: 

Maybe you could serialize a DataTable, but keep in mind if you fill it with data this can get large and take serious amount of time to serialize or deserialize. If data is stored otherwise, you might want to store column info in a config/project file.

HTH, -sa

Sascha
@Sascha,Data will be almost of 10 rows and 10 columns maximum.
Harikrishna
+1  A: 

Use a database. If you don't want the hassle of setting up a client/sever architecture, use SQLite, which has several .Net incarnations, or SQL Server Express.

Marcelo Cantos
+1  A: 

An alternative to database is: http://www.filehelpers.com/

Aseem Gautam
+1 for the filehelpers!
KMan
+1  A: 

You can use an XML files as an alternative, though using SQLite seems much more preferable. XML facilities are located under a System.Xml namespace. You can use XMLReader/Writer class to manage an information in you files. There are some good usage examples on the MSDN page.

n535
@n535,How to store and retrieve the data to xml file ?
Harikrishna
@Harikrishna, you need to do at least some of the thinking here.
Marcelo Cantos
A: 

If you've got-to-choose but a database; then I'd go with Xml, use SAX to parse when file goes larger.

See how to Manipulate XML File Data Using C#

--EDIT--

This is in response to your comment. Lets assume that you have a screen with following controls:

  1. TextBox as txtColumnName; when user provides a column name and click on the add button, save it as an xml attribute.
  2. ComboBox as cbxColumns; select the current column
  3. TextBox as txtValue; when this is provided then save the value in the column selected in the Columns combo.
  4. Add Button; you can add delete, update buttons as well.

Please go through the example link, it would help you add/remove/update nodes at runtime. You can comeup with your XmlDatabaseWrapper class that would wrap around all of the CRUD operations.

KMan
@KMan, Data will not be more than 10 rows by 10 columns.
Harikrishna
@Harikrishna: Well, you can use DOM in that case. Although it sounds like you aren't in favor of xml, and if so, then in that case I'd save/retrieve the custom object in binary. Or better http://www.filehelpers.com/ looks worth looking into as proposed by Aseem.
KMan
@KMan,No I would like to use xml for that.But how can I store the data in xml file that user will input and how to retrieve them ?
Harikrishna
@Harikrishna : This will change depending the data you have to store. You have to put some thoughts into this. The same way you think about how the data will be stored on a DB, you have to think HOW the data will be saved to the XML file.
Frank
@Harikrishna: Please see my edit in response to your comment.
KMan
@Harikrishna: Like I've said before, I do not think SAX/DOM parsing is the best way to go. It's tedious and relatively hard to understand for someone reviewing your code.
Frank
@KMan,Thanks...
Harikrishna
A: 

If it's just ten columns how about storing as a delimited string in App.Config?

Simon
@Simon,how can we store in App.Config ?
Harikrishna
A: 

I think using XML files will be your best option.

Take a look at this article which clearly shows how to manipulate XML file.

http://www.developer.com/article.php/3489611

HTH

Raja
+6  A: 

Lots of people have been talking about XML, it's a good idea. However, if Linq is available for you, you shoudl really consider using Linq to XML instead of SAX/DOM parsing.

Linq to XML makes it easier to parse, create and edit XML file compared to SAX and DOM parser. Using SAX/DOM parsing usually requires a lot of loops to get to the correct element or to navigate trough the nodes.

Example taken from MSDN :
Using DOM Parsing :

XmlDocument doc = new XmlDocument();
XmlElement name = doc.CreateElement("Name");
name.InnerText = "Patrick Hines";
XmlElement phone1 = doc.CreateElement("Phone");
phone1.SetAttribute("Type", "Home");
phone1.InnerText = "206-555-0144";        
XmlElement phone2 = doc.CreateElement("Phone");
phone2.SetAttribute("Type", "Work");
phone2.InnerText = "425-555-0145";        
XmlElement street1 = doc.CreateElement("Street1");        
street1.InnerText = "123 Main St";
XmlElement city = doc.CreateElement("City");
city.InnerText = "Mercer Island";
XmlElement state = doc.CreateElement("State");
state.InnerText = "WA";
XmlElement postal = doc.CreateElement("Postal");
postal.InnerText = "68042";
XmlElement address = doc.CreateElement("Address");
address.AppendChild(street1);
address.AppendChild(city);
address.AppendChild(state);
address.AppendChild(postal);
XmlElement contact = doc.CreateElement("Contact");
contact.AppendChild(name);
contact.AppendChild(phone1);
contact.AppendChild(phone2);
contact.AppendChild(address);
XmlElement contacts = doc.CreateElement("Contacts");
contacts.AppendChild(contact);
doc.AppendChild(contacts);

Using Linq to XML :

XElement contacts =
    new XElement("Contacts",
        new XElement("Contact",
            new XElement("Name", "Patrick Hines"),
            new XElement("Phone", "206-555-0144", 
                new XAttribute("Type", "Home")),
            new XElement("phone", "425-555-0145",
                new XAttribute("Type", "Work")),
            new XElement("Address",
                new XElement("Street1", "123 Main St"),
                new XElement("City", "Mercer Island"),
                new XElement("State", "WA"),
                new XElement("Postal", "68042")
            )
        )
    );

Easier to do and much more clear.

Edit:
Save the XML tree to contacts.xml :

// using the code above
contact.Save("contacts.xml");

Load the contacts.xml file :

//using the code above
XDocument contactDoc = XDocument.Load("contacts.xml"); 

To update an element of the tree there is a few functions in the doc that can do it depending on what you want to do

Frank
+1 Good idea - Linq to Xml.
KMan
Could you expand your answer to target the edited version of the question? You did a great job of illustrating the programmatic differences between XML document initialization in 2.0 and 3.5, but no explanation of how to update, serialize, etc.
Dathan
@Dathan : There you go, I hope it can help :)
Frank
@Frank,Thanks.....Great and descriptive answer.
Harikrishna