如何在不使用数据库的情况下存储数据以及如何检索它们?

Har*_*hna 4 .net c# winforms

我正在解析html文件以通过列名提取表格信息.我希望让用户为列名提供输入.并根据该列名称将提取表格信息.

现在,用户将输入的列名称,根据该列名称,我想从html文件中找到表格信息.

但是我应该在哪里存储用户输入的列名?以及如何检索它们?我不想使用数据库.

编辑:我们如何在xml文件中存储数据以及如何从中检索数据以及如何更新xml文件以存储数据?像我有3种名Name, Address,Phone no和该用户将输入可能列名状Nm,Add,PhNo.Nam,Addre,PhoNo等.

ALO*_*low 10

很多人一直在谈论XML,这是一个好主意.但是,如果是的LINQ提供给你,你shoudl 真的考虑使用LINQ到XML,而不是SAX/DOM解析.

与SAX和DOM解析器相比,Linq to XML使得解析,创建和编辑XML文件变得更容易.使用SAX/DOM解析通常需要大量循环来获取正确的元素或通过节点导航.

从MSDN获取的示例:
使用DOM解析:

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);
Run Code Online (Sandbox Code Playgroud)

使用Linq到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")
            )
        )
    );
Run Code Online (Sandbox Code Playgroud)

更容易做,更清晰.

编辑:
将XML树保存到contacts.xml:

// using the code above
contact.Save("contacts.xml");
Run Code Online (Sandbox Code Playgroud)

加载contacts.xml文件:

//using the code above
XDocument contactDoc = XDocument.Load("contacts.xml"); 
Run Code Online (Sandbox Code Playgroud)

要更新树的元素,doc中有一些函数可以根据您的要求执行此操作