How to do curd operations on XML Which Shown Below
-
<Messages>
<category Name="Main">
<message id="1" title="one" name="Name1" Description="Description1">
</message>
</category>
<category Name="Main1">
<message id="2" title="two" name="Name2" Description="Description2">
</message>
</category> -
<Messages>
<category Name="Main">
<message id="1" title="one" name="Name1" Description="Description1">
</message>
</category>
<category Name="Main1">
<message id="2" title="two" name="Name2" Description="Description2">
</message>
</category> -
<Messages>
<category Name="Main">
<message id="1" title="one" name="Name1" Description="Description1">
</message>
</category>
<category Name="Main1">
<message id="2" title="two" name="Name2" Description="Description2">
</message>
</category>public static string filePath = HttpContext.Current.Server.MapPath("~/App_Data/Messages.xml");
public static XmlDocument xmlDoc = new XmlDocument();XmlNode _xmlNode = xmlDoc.CreateElement("category"); XmlAttribute _xmlCategoryName = xmlDoc.CreateAttribute("Name"); _xmlCategoryName.Value = categoryName; _xmlNode.Attributes.Append(_xmlCategoryName); // Add Message Node XmlElement _xmlElement = xmlDoc.CreateElement("message"); XmlAttribute _xmlId = xmlDoc.CreateAttribute("id"); _xmlId.Value = Convert.ToString(ID); _xmlElement.Attributes.Append(_xmlId); XmlAttribute _xmltitle = xmlDoc.CreateAttribute("title"); _xmltitle.Value = Convert.ToString(title); _xmlElement.Attributes.Append(_xmltitle); XmlAttribute _xmlname = xmlDoc.CreateAttribute("name"); _xmlname.Value = Convert.ToString(name); _xmlElement.Attributes.Append(_xmlname); XmlAttribute _xmlDescription = xmlDoc.CreateAttribute("Description"); _xmlDescription.Value = Convert.ToString(description); _xmlElement.Attributes.Append(_xmlDescription); _xmlNode.AppendChild(_xmlElement); xmlDoc.DocumentElement.AppendChild(_xmlNode);
-
<Messages>
<category Name="Main">
<message id="1" title="one" name="Name1" Description="Description1">
</message>
</category>
<category Name="Main1">
<message id="2" title="two" name="Name2" Description="Description2">
</message>
</category>This is not the document you want for figuring out CRUD. You need the XSD to do that properly. You could guess and as long as the database column names matched you *might* be able to guess correctly, but...I would not be helping you if I recommended that you do that. If you can write your own query to select a row and if you also had access to ADO.NET -- you could have the table tell you its schema and then the query could be written properly. This method that you are using -- is not a great idea -- you can have some success in doing it, but not for long and it is very likely that you will manage to put a row in the database that will be junk data because you do not know the schema -- you are just making blind CRUD operations. A better choice might be stored procedures because you can just provide the parameters from the client side. At any rate, the less you count on being smart on the client side, the better off you will be.