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>
<price>999</price>
</book>
</bookstore>
2 bookstore.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace toxml
{
public class ToXml
{
public static void Main(string[] args)
{
//实例化一个XmlDocument对象
XmlDocument xmlDoc = new XmlDocument();
//实例对象读取要写入的XML文件
xmlDoc.Load("bookstore.xml");
//查找<bookstore>
XmlNode root = xmlDoc.SelectSingleNode("bookstore");
//创建一个<book>节点
XmlElement xe1 = xmlDoc.CreateElement("book");
//设置该节点genre属性
xe1.SetAttribute("leixing", "music");
//设置该节点ISBN属性
xe1.SetAttribute("ISBN", "56756");
 
相关文档:
一、首先先添加引用 using Microsoft.Win32;
//因为操作注册表的两个类RegistryKey和Registry都包含在此引用中;
二、编写代码开始操作注册表
1、 #region 限制软件的使用次数
pri ......
Ajax和jsp的怪现象
如果用Ajax去请求一个jsp页面,该jsp页面返回的是xml(response.setContentType("text/xml; charset=GB2312");),并且该jsp包含下面这些头@page指令的话,则在客户端xml=XMLHttpRequest.responseXML得到的是一个不包含任务东西的xml对象,即xml.childNodes.length将会是0.
......
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文件
/// ......
ZT:http://www.mobpub.net/archiver/?tid-28.html
Symbian学习笔记(15)——解析XML文件(上)
今天想分享的是如何在Symbian平台上解析XML文件,不需要第三方的东西,Symbian已经为我们提供了这个类CParser。
网上也有这方面的资料,建议参考:
[url]http://wiki.forum.nokia.com/index.php/How_to_parse_XML_fi ......
MSXML2::IXMLDOMDocumentPtr pDoc;
MSXML2::IXMLDOMElementPtr xmlRoot ;
// 创建DOMDocument对象
HRESULT hr = pDoc.CreateInstance(__uuidof(MSXML2::DOMDocument40));
if ( ! SUCCEEDED(hr))
{
MessageBox( " 无法创建DOMDocument对象,请检查 ......