如何存储数据,而无需使用数据库,以及如何找回它们? [英] How to Store data without using Database and how to retrieve them?

查看:160
本文介绍了如何存储数据,而无需使用数据库,以及如何找回它们?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我解析HTML文件,通过列名来提取表格信息。我想喜欢让用户得到输入列名。按照该列名表格信息将被提取。

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.

现在的列名其中用户输入的基础上,我想找到从HTML文件中的表格信息的列名。

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.

修改:我们如何可以存储在XML文件中的数据以及如何才能从中检索数据,以及我们如何可以更新用于存储数据的XML文件?像我有3列名姓名,地址,电话号码和该用户会喜欢输入可能列名牛米,添加,PHNO。南,Addre,PHONO 等等。

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.

推荐答案

很多人都在谈论XML,这是一个好主意。但是,如果LINQ的可用于你,你shoudl的真的考虑使用的的LINQ to XML而不是SAX / DOM解析

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可以更容易地分析,创建并与SAX和DOM解析器编辑XML文件。使用SAX / DOM分析通常需要大量的循环,以获得正确的元素或导航槽的节点。

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.

例如,从MSDN采取:
使用DOM解析:

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);

使用LINQ to XML:

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.

编辑:
保存XML树contacts.xml:


Save the XML tree to contacts.xml :

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

加载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

这篇关于如何存储数据,而无需使用数据库,以及如何找回它们?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆