using
System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Gis.GetInfo.GisNode;
namespace Gis.GetInfo.ItemSub
{
/// <summary>
/// 表示GetINFO节点下的唯一的一种节点
/// </summary>
public class ItemSub
{
/// <summary>
/// ItemSub的名字
/// </summary>
internal string m_str_name = null;
/// <summary>
/// ItemSub的节点,Xml节点
/// </summary>
internal XmlNode m_Xmlnode_node;
/// <summary>
/// ItemSub下的CisNode
/// </summary>
internal GisNodeCollection m_collect_node;
/// <summary>
/// 通过索引器访问子结点
/// </summary>
/// <param name="index">int.索引从零开始</param>
public GisNode.GisNode this[int index]
{
get { return m_collect_node[index]; }
}
/// <summary>
/// 通过索引器访问子结点
/// </summary>
/// <param name="name">string.子节点名字</param>
public GisNode.GisNode this[string name]
{
get
{
foreach (GisNode.GisNode cisn in m_collect_node)
{
if (cisn.Name == name)
return cisn;
}
return null;
}
}
/// <summary>
/// 初始化一个ItemSub类
/// </summary>
/// <param name="ItemSubNode">XmlNode.表示ItemSub的Xml节点。</param>
/// <param name="htmldoc">html文档</param>
public ItemSub(XmlNode ItemSubNode)
{
if (ItemSubNode.Attributes["Name"] == null) throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeNotFound, ItemSubNode);
else if (ItemSubNode.Attributes["Name"].Value == "") throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeIsEmpty, ItemSubNode);
else m_str_name = ItemSubNode.Attributes["Name"].Value;
m_Xmlnode_node = ItemSubNode.CloneNode(true);
Exception ex;
Check(ItemSubNode, out ex);
if (ex != null)
{
if (ex is GisException) throw new Exception((ex as GisException).ToString());
else throw ex;
}
IList<GisNode.GisNode> l = new List<GisNode.GisNode>();
foreach (XmlNode n in ItemSubNode.ChildNodes)
{
switch (GisNode.GisNode.IsWhichType_Easily(n))
{
case Gis.GetInfo.GisNode.NodeType_GisNode.Common:
{
GisNode.CommonNode temp = new GisNode.CommonNode(n, false);
l.Add(temp);
break;
}
case Gis.GetInfo.GisNode.NodeType_GisNode.for_each:
{
GisNode.ForEachNode temp = new Gis.GetInfo.GisNode.ForEachNode(n, false);
l.Add(temp);
break;
}
default:
{ break; }
}
}
m_collect_node = new Gis.GetInfo.GisNode.GisNodeCollection(l);
}
/// <summary>
/// Check ItemSub Is True
/// </summary>
/// <param name="ItemSubNode">XmlNode。ItemSub节点</param>
/// <param name="Oex">out.指示出错的异常的描述</param>
public static bool Check(XmlNode ItemSubNode, out Exception Oex)
{
if (ItemSubNode == null) { Oex = new ArgumentNullException("GetInfoNode"); return false; }
if (ItemSubNode.ChildNodes.Count == 0) { Oex = new GisException(ExceptionAt.GetInfo, ExceptionType.ChildNodeIsTooLess, ItemSubNode); return false; }
//if (GetInfoNode.Name != "GetINFO") { Oex = new ArgumentException("传入的节点名字不是GetINFO!"); return false; }
foreach (XmlNode n in ItemSubNode)
{
Exception ex;
switch (GisNode.GisNode.IsWhichType_Easily(n))
{
case GisNode.NodeType_GisNode.Common:
{
ex = GisNode.CommonNode .CheckIsCommonNode(n);
if (ex == null) continue;
else { Oex = ex; return false; }
}
case GisNode.NodeType_GisNode.for_each:
{
ex = GisNode.ForEachNode .CheckIsForEachNode(n);
if (ex == null) continue;
else { Oex = ex; return false; }
}
}
}
Oex = null;
return true;
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Gis.GetInfo.GisNode;
namespace Gis.GetInfo.ItemSub
{
/// <summary>
/// 表示GetINFO节点下的唯一的一种节点
/// </summary>
public class ItemSub
{
/// <summary>
/// ItemSub的名字
/// </summary>
internal string m_str_name = null;
/// <summary>
/// ItemSub的节点,Xml节点
/// </summary>
internal XmlNode m_Xmlnode_node;
/// <summary>
/// ItemSub下的CisNode
/// </summary>
internal GisNodeCollection m_collect_node;
/// <summary>
/// 通过索引器访问子结点
/// </summary>
/// <param name="index">int.索引从零开始</param>
public GisNode.GisNode this[int index]
{
get { return m_collect_node[index]; }
}
/// <summary>
/// 通过索引器访问子结点
/// </summary>
/// <param name="name">string.子节点名字</param>
public GisNode.GisNode this[string name]
{
get
{
foreach (GisNode.GisNode cisn in m_collect_node)
{
if (cisn.Name == name)
return cisn;
}
return null;
}
}
/// <summary>
/// 初始化一个ItemSub类
/// </summary>
/// <param name="ItemSubNode">XmlNode.表示ItemSub的Xml节点。</param>
/// <param name="htmldoc">html文档</param>
public ItemSub(XmlNode ItemSubNode)
{
if (ItemSubNode.Attributes["Name"] == null) throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeNotFound, ItemSubNode);
else if (ItemSubNode.Attributes["Name"].Value == "") throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeIsEmpty, ItemSubNode);
else m_str_name = ItemSubNode.Attributes["Name"].Value;
m_Xmlnode_node = ItemSubNode.CloneNode(true);
Exception ex;
Check(ItemSubNode, out ex);
if (ex != null)
{
if (ex is GisException) throw new Exception((ex as GisException).ToString());
else throw ex;
}
IList<GisNode.GisNode> l = new List<GisNode.GisNode>();
foreach (XmlNode n in ItemSubNode.ChildNodes)
{
switch (GisNode.GisNode.IsWhichType_Easily(n))
{
case Gis.GetInfo.GisNode.NodeType_GisNode.Common:
{
GisNode.CommonNode temp = new GisNode.CommonNode(n, false);
l.Add(temp);
break;
}
case Gis.GetInfo.GisNode.NodeType_GisNode.for_each:
{
GisNode.ForEachNode temp = new Gis.GetInfo.GisNode.ForEachNode(n, false);
l.Add(temp);
break;
}
default:
{ break; }
}
}
m_collect_node = new Gis.GetInfo.GisNode.GisNodeCollection(l);
}
/// <summary>
/// Check ItemSub Is True
/// </summary>
/// <param name="ItemSubNode">XmlNode。ItemSub节点</param>
/// <param name="Oex">out.指示出错的异常的描述</param>
public static bool Check(XmlNode ItemSubNode, out Exception Oex)
{
if (ItemSubNode == null) { Oex = new ArgumentNullException("GetInfoNode"); return false; }
if (ItemSubNode.ChildNodes.Count == 0) { Oex = new GisException(ExceptionAt.GetInfo, ExceptionType.ChildNodeIsTooLess, ItemSubNode); return false; }
//if (GetInfoNode.Name != "GetINFO") { Oex = new ArgumentException("传入的节点名字不是GetINFO!"); return false; }
foreach (XmlNode n in ItemSubNode)
{
Exception ex;
switch (GisNode.GisNode.IsWhichType_Easily(n))
{
case GisNode.NodeType_GisNode.Common:
{
ex = GisNode.CommonNode .CheckIsCommonNode(n);
if (ex == null) continue;
else { Oex = ex; return false; }
}
case GisNode.NodeType_GisNode.for_each:
{
ex = GisNode.ForEachNode .CheckIsForEachNode(n);
if (ex == null) continue;
else { Oex = ex; return false; }
}
}
}
Oex = null;
return true;
}
}
}
using
System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Gis.GetInfo.ItemSub
{
/// <summary>
/// ItemSub的集合类
/// </summary>
public class ItemSubCollection
{
/// <summary>
/// ItemSub集合
/// </summary>
private List<ItemSub> m_lst;
/// <summary>
/// 初始化一个ItemSubCollection类,处理ItemSub的集合节点
/// </summary>
/// <param name="ItemSubNodeParent">一个GetINFO节点,也就是ItemSub项的父节点</param>
/// <param name="htmldoc">html文档</param>
public ItemSubCollection(XmlNode ItemSubNodeParent, HtmlAgilityPack.HtmlDocument htmldoc)
{
if (ItemSubNodeParent == null) throw new ArgumentNullException("ItemSubNode");
if (ItemSubNodeParent.ChildNodes.Count == 0) throw new GisException(ExceptionAt.GetInfo,
ExceptionType.ItemSubCountIsZero, ItemSubNodeParent);
System.Collections.ArrayList namelst = new System.Collections.ArrayList();
for (int i = 0; i < ItemSubNodeParent.ChildNodes.Count; i++)
{
if (ItemSubNodeParent.ChildNodes[i].Name != "ItemSub")
throw new GisException(ExceptionAt.GetInfo, ExceptionType.FileStructNotRule, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes.Count > 1)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeTooMany, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes.Count == 0)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeTooLess, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes["Name"] == null)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeNotFound, ItemSubNodeParent.ChildNodes[i]);
else if (namelst.IndexOf(ItemSubNodeParent.ChildNodes[i].Attributes["Name"].Value) != -1)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.ItemSubNameIsRepeat, ItemSubNodeParent.ChildNodes[i]);
else namelst.Add(ItemSubNodeParent.ChildNodes[i].Attributes["Name"].Value);
}
m_lst = new List<ItemSub>(ItemSubNodeParent.ChildNodes.Count);
foreach (XmlNode n in ItemSubNodeParent)
{
m_lst.Add(new ItemSub(n));
}
List<string> lst = new List<string>(m_lst.Count);
foreach (ItemSub it in m_lst)
{
if (lst.Contains(it.m_str_name))
throw new GisException(ExceptionAt.GetInfo, ExceptionType.ItemSubNameIsRepeat, it.m_Xmlnode_node);
lst.Add(it.m_str_name);
}
}
/// <summary>
/// 通过索引访问集合项
/// </summary>
/// <param name="index">Int32.索引值,从0开始索引。</param>
public ItemSub this[int index]
{
get { return m_lst[index]; }
}
/// <summary>
/// 通过ItemSub的Name属性来查看ItemSub项
/// </summary>
/// <param name="name">ItemSub的Name属性,若没有找到则返回null(VB中为Nothing)</param>
public ItemSub this[string name]
{
get
{
foreach (ItemSub isub in m_lst)
{
if (isub.m_str_name == name)
return isub;
}
return null;
}
}
/// <summary>
/// 返回集合项的数目。
/// </summary>
public int Count
{
get { return m_lst.Count; }
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Xml;
namespace Gis.GetInfo.ItemSub
{
/// <summary>
/// ItemSub的集合类
/// </summary>
public class ItemSubCollection
{
/// <summary>
/// ItemSub集合
/// </summary>
private List<ItemSub> m_lst;
/// <summary>
/// 初始化一个ItemSubCollection类,处理ItemSub的集合节点
/// </summary>
/// <param name="ItemSubNodeParent">一个GetINFO节点,也就是ItemSub项的父节点</param>
/// <param name="htmldoc">html文档</param>
public ItemSubCollection(XmlNode ItemSubNodeParent, HtmlAgilityPack.HtmlDocument htmldoc)
{
if (ItemSubNodeParent == null) throw new ArgumentNullException("ItemSubNode");
if (ItemSubNodeParent.ChildNodes.Count == 0) throw new GisException(ExceptionAt.GetInfo,
ExceptionType.ItemSubCountIsZero, ItemSubNodeParent);
System.Collections.ArrayList namelst = new System.Collections.ArrayList();
for (int i = 0; i < ItemSubNodeParent.ChildNodes.Count; i++)
{
if (ItemSubNodeParent.ChildNodes[i].Name != "ItemSub")
throw new GisException(ExceptionAt.GetInfo, ExceptionType.FileStructNotRule, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes.Count > 1)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeTooMany, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes.Count == 0)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeTooLess, ItemSubNodeParent.ChildNodes[i]);
if (ItemSubNodeParent.ChildNodes[i].Attributes["Name"] == null)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.AttributeNotFound, ItemSubNodeParent.ChildNodes[i]);
else if (namelst.IndexOf(ItemSubNodeParent.ChildNodes[i].Attributes["Name"].Value) != -1)
throw new GisException(ExceptionAt.GetInfo, ExceptionType.ItemSubNameIsRepeat, ItemSubNodeParent.ChildNodes[i]);
else namelst.Add(ItemSubNodeParent.ChildNodes[i].Attributes["Name"].Value);
}
m_lst = new List<ItemSub>(ItemSubNodeParent.ChildNodes.Count);
foreach (XmlNode n in ItemSubNodeParent)
{
m_lst.Add(new ItemSub(n));
}
List<string> lst = new List<string>(m_lst.Count);
foreach (ItemSub it in m_lst)
{
if (lst.Contains(it.m_str_name))
throw new GisException(ExceptionAt.GetInfo, ExceptionType.ItemSubNameIsRepeat, it.m_Xmlnode_node);
lst.Add(it.m_str_name);
}
}
/// <summary>
/// 通过索引访问集合项
/// </summary>
/// <param name="index">Int32.索引值,从0开始索引。</param>
public ItemSub this[int index]
{
get { return m_lst[index]; }
}
/// <summary>
/// 通过ItemSub的Name属性来查看ItemSub项
/// </summary>
/// <param name="name">ItemSub的Name属性,若没有找到则返回null(VB中为Nothing)</param>
public ItemSub this[string name]
{
get
{
foreach (ItemSub isub in m_lst)
{
if (isub.m_str_name == name)
return isub;
}
return null;
}
}
/// <summary>
/// 返回集合项的数目。
/// </summary>
public int Count
{
get { return m_lst.Count; }
}
}
}