62,074
社区成员
发帖
与我相关
我的任务
分享
<?xml version="1.0" encoding="utf-8" ?>
<xmlroot>
<shoptemplate text="大众点评" myspace="dzdp" class="dzdp.CInfoCls">
<channel text="咖啡厅">search/category/4/30/g2027</channel>
<channel text="酒吧">search/category/4/30/g2029</channel>
<channel text="茶馆">search/category/4/30/g2025</channel>
<channel text="KTV">search/category/4/30/g4807</channel>
<channel text="电影院">search/category/4/30/g4782</channel>
<channel text="文化艺术">search/category/4/30/g4755</channel>
<channel text="景点/郊游">search/category/4/30/g4784</channel>
<channel text="公园">search/category/4/30/g4802</channel>
<channel text="足疗按摩">search/category/4/30/g4793</channel>
<channel text="桑拿水会">search/category/4/30/g4778</channel>
<channel text="游乐游艺">search/category/4/30/g4788</channel>
<channel text="桌面游戏">search/category/4/30/g6696</channel>
<channel text="桌球室">search/category/4/30/g24677</channel>
<channel text="DIY手工坊">search/category/4/30/g4762/g30g4762</channel>
</shoptemplate>
<newstemplate text="瑞丽女性网" myspace="rayli" class="rayli.CInfoCls">
<channel text="瑞丽夜店">zixun/LT_407604.html</channel>
<channel text="瑞丽酒吧">zixun/LT_379668.html</channel>
</newstemplate>
</xmlroot>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Web;
namespace DME.Collector
{
/// <summary>
/// 配置文件SiteConfig.xml
/// </summary>
public static class SiteConfig
{
/// <summary>
/// 配置文件路径 路径"/SiteConfig.xml"
/// </summary>
private static string _FilePath = "\\SiteConfig.Config";
public static string FilePath { get { return _FilePath; } set { _FilePath = value; } }
/// <summary>
/// 根节点对象
/// </summary>
public static xmlroot xmlroot()
{
XmlSerializer xs = new XmlSerializer(typeof(xmlroot));
Stream stream;
string strpath = "SiteConfig.xml";
try
{
stream = new FileStream(strpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return (xmlroot)xs.Deserialize(stream);
}
catch
{
return FormatConfig();
}
}
public static xmlroot FormatConfig()
{
xmlroot RT = new xmlroot();
try
{
XmlSerializer xs = new XmlSerializer(typeof(xmlroot));
Stream stream = new FileStream("SiteConfig.xml", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
xs.Serialize(stream, RT);
stream.Close();
return RT;
}
catch
{
return null;
}
}
}
/// <summary>
/// 序列化对象类,根节点root
/// </summary>
[XmlRoot("root")]
public class xmlroot
{
public List<template> shoptemplate;
public List<template> newstemplate;
}
/// <summary>
/// 序列化对象类,子节点 root》template
/// </summary>
[Serializable]
public class template {
private string _text;
[XmlAttribute("text")]
public string text { get { return _text; } set { _text = value; } }
private string _space;
[XmlAttribute("space")]
public string space { get { return _space; } set { _space = value; } }
private string _class;
[XmlAttribute("class")]
public string Class { get { return _class; } set { _class = value; } }
private List<channel> _channel;
[XmlElement(ElementName = "channel")]
public List<channel> channel { get { return _channel; } set { _channel = value; } }
}
/// <summary>
/// 序列化对象类,子节点 root》template》channel
/// </summary>
[Serializable]
public class channel {
private string _text;
[XmlAttribute("text")]
public string text { get { return _text; } set { _text = value; } }
}
}
try
{
stream = new FileStream(strpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
return (xmlroot)xs.Deserialize(stream);
}
catch
{
return FormatConfig();
}