C # preliminary XML operations (5)
Chapter 2: Add records to existing XML files
In addition, C # provides a more convenient way for us to operate XML, that is, DATASET
In fact, we can think that DATASET is actually multiple XML files. Using DATASET's built-in methods and attributes to operate XML is very flexible.
Let's continue to assume that an existing XML file is as follows: <? Xml version = "1.0" encoding = "gb2312"?>
<Users>
<User id = "1">
<UserName> outrace </userName>
<UserPass> mypass </userPass>
</User>
<User id = "2">
<UserName> trace </userName>
<UserPass> mypass </userPass>
</User>
</Users>
Write the following code <% @ Import Namespace = "System. IO" %>
<% @ Import Namespace = "System. Xml" %>
<% @ Import Namespace = "System. Data" %>
<Script Language = "C #" Runat = "Server" Debug = "true">
Public void Page_Load (Object src, EventArgs e)
{
/*
* Copyright: copyright by SEM IT DEPARTMENT
* Version: version 0.0.1
* File: InsertXml_2.aspx
* Usage: add data to XML using DATASET
* Author: Ouyang Yuntian @ 2005-4-9
* Mail: outrace@soueast-motor.com
* Modification:
*/
String fileName;
FileName = "users_2.xml ";
DataSet myDs = new DataSet ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.