易截截图软件、单文件、免安装、纯绿色、仅160KB

C#修改XML的简单例子

接上一篇《C#写XML的简单例子》
这个例子要修改XML文件中结点的属性和和元素的文本
1 原xml文件 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
    <price>999</price>
  </book>
  <book leixing="music" ISBN="56756">
    <title>CS从入门到精通</title>
    <author>候捷</author>
    <price>222</price>
  </book>
</bookstore>
2 program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //实例化一个XmlDocument对象
            XmlDocument xmlDoc = new XmlDocument();
            //实例对象读取要写入的XML文件
            xmlDoc.Load("bookstore.xml");
            //获取bookstore节点的所有子节点
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("bookstore").ChildNodes;
            //遍历所有子节点
            foreach (XmlNode xn in nodeList)
            {
                //将子节点类型


相关文档:

XML 增删改查

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Xml;
using System.Data;
public class Cls_XML
{
    #region 创建xml文件
    /// <summary>
    /// 创建xml文件
    /// ......

VC读写XML文件

MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMElementPtr  xmlRoot ;
 // 创建DOMDocument对象
 HRESULT hr  =  pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
 if ( ! SUCCEEDED(hr))
  { 
 MessageBox( " 无法创建DOMDocument对象,请检查 ......

dom4j读取xml文件例子

package com.test.dom4j;
import java.io.*;
import java.util.*;
import org.dom4j.*;
import org.dom4j.io.*;
public class MyXMLReader {
public static void main(String arge[]) {
try {
File f = new File("src/testxml.xml");
SAXReader reader = new SAXReader();
Document doc = reader.rea ......

C#写XML的简单例子

这个例子要把bookstore.xml文件增加一条book记录
1 bookstore.xml
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
  <book genre="love" ISBN="1234123">
    <title>who am i </title>
    <author>who</author>
   ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号