XML操作备忘录

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common
{
    /// <summary>
    /// 节点属性类
    /// </summary>
    public class Attributes
    {
        string attributename;
        /// <summary>
        /// 节点属性名称
        /// </summary>
        public string Attributename
        {
            get { return attributename; }
            set { attributename = value; }
        }
        string attributevalue;
        /// <summary>
        /// 节点属性值
        /// </summary>
        public string Attributevalue
        {
            get { return attributevalue; }
            set { attributevalue = value; }
        }
        public Attributes(string attributename, string attributevalue)
        {
            this.attributename = attributename;
            this.attributevalue = attributevalue;
        }
        public Attributes()
        { }
    }
   public  class UserXml
    {
       /// <summary>
       /// 创建XML文件
       /// </summary>
       /// <param name="filename">XML文件路径</param>
       /// <param name="encoding">编码方式</param>
       /// <param name="RootNode">根节点名称</param>
       /// <returns>XMLDOCUMENT</returns>
       public XmlDocument CreateXmlFile(string filename,string encoding,string RootNode)
       {
           XmlDocument xmldoc = new XmlDocument();
           XmlNode node = xmldoc.CreateXmlDeclaration("1.0", encoding, null);
           xmldoc.AppendChild(node);
           XmlNode root = xmldoc.CreateElement(RootNode);
           xmldoc.AppendChild(root);
           xmldoc.Save(filename);
           return xmldoc;
       }
        /// <summary>
        /// 加载XML文件
        /// </summary>
        /// <param name="filename">Xml文件路径</param>
        /// <returns></returns>
        public XmlDocument LoadXml(string filename)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(filename);
            return xmldoc;
        }
        /// <summary>
        /// 添加新节点
        /// </summary>
        /// <param name="xmldoc">XMLDOCUMENT对象</param>
        /// <param name="parentnode">新节点的父节点</param>
        /// <param name="name">新节点的名称</param>
        /// <param name="value">新节点的值</param>
        /// <param name="hasAttributes">是否有属性</param>
        ///   <param name="attributes">节点属性类的数组</param>
        /// <returns>新节点</returns>
          public XmlNode CreateNode(XmlDocument xmldoc, XmlNode parentnode, string name, string value, bool hasAttribute,
            params Attributes[] attributes)
        {
            XmlNode newnode = xmldoc.CreateElement(name);
            newnode.InnerText = value;
            if (hasAttribute)
            {
                foreach (Attributes att in attributes)
                {
                    XmlAttribute tempattribute = xmldoc.CreateAttribute(att.Attributename);
                    tempattribute.InnerText = att.Attributevalue;
                    newnode.Attributes.Append(tempattribute);
                }
            }
            parentnode.AppendChild(newnode);
            return newnode;
        }
        /// <summary>
        /// 查询单个节点
        /// </summary>
        /// <param name="xmldoc">XmlDocument文档对象</param>
        /// <param name="xpath">Xpath表达式</param>
        /// <returns></returns>
        public XmlNode SelectNode(XmlDocument xmldoc, string xpath)
        {
            XmlNode node = xmldoc.SelectSingleNode(xpath);
            return node;

        }
        public XmlNodeList SelectNodeList(XmlDocument xmldoc, string xpath)
        {
            XmlNodeList list = xmldoc.SelectNodes(xpath);
            return list;
        }

    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
android备忘录文档主要代码包括以下几个方面: 1. 布局文件代码:主要用于定义备忘录应用程序的界面布局。可以使用LinearLayout、RelativeLayout等布局容器,通过XML语言设置控件的位置、大小、样式等属性,如EditText用于输入备忘录内容,Button用于保存或删除备忘录等。 2. Java类代码:主要用于处理备忘录应用程序的逻辑。其中包括定义备忘录类和主活动类。备忘录类用于存储备忘录的相关信息,如标题、内容、时间等。主活动类用于处理用户与界面的交互操作,如保存备忘录、删除备忘录、展示备忘录列表等。 3. 数据库操作代码:用于创建和管理备忘录的数据库。可以使用SQLite数据库来存储备忘录的信息。数据库操作代码包括创建数据库、定义表结构、插入备忘录、更新备忘录、删除备忘录操作。 4. 适配器类代码:用于将备忘录数据适配到界面上。适配器类继承自RecyclerView.Adapter类,重写其中的方法,实现备忘录数据和界面的绑定。 5. 点击事件监听器代码:用于处理备忘录列表中备忘录项的点击事件。可以设置RecyclerView的点击事件监听器,在点击时打开备忘录详情页面。 以上是android备忘录文档主要代码的概述,实际开发过程中还需要根据需求进行具体的定制和实现。通过合理地组织和编写代码,可以实现一个功能完善、易用的备忘录应用程序。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值