Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.Xml.Linq;
- namespace Delta_9_Test.Util
- {
- public class XMLEntry
- {
- private string type = "";
- private string text = "";
- private Dictionary<string, XMLEntry> children;
- private Dictionary<int, XMLEntry> group;
- private Dictionary<string, string> attributes;
- public string Type
- {
- get { return type; }
- }
- public string Text
- {
- get { return text; }
- set { text = value; }
- }
- public Dictionary<string, XMLEntry> Children
- {
- get
- {
- return children;
- }
- }
- public Dictionary<int, XMLEntry> Group
- {
- get
- {
- return group;
- }
- }
- public Dictionary<string, string> Attributes
- {
- get
- {
- return attributes;
- }
- }
- public XMLEntry GetProperty(string name)
- {
- if (children.ContainsKey(name))
- return children[name];
- return null;
- }
- public int GetPropertyCount()
- {
- return children.Count;
- }
- public string GetAttribute(string name)
- {
- if (attributes.ContainsKey(name))
- return attributes[name];
- return null;
- }
- public int GetAttributeCount()
- {
- return attributes.Count;
- }
- public XMLEntry(XmlReader r)
- {
- this.children = new Dictionary<string, XMLEntry>();
- this.group = new Dictionary<int, XMLEntry>();
- this.attributes = new Dictionary<string, string>();
- this.type = r.Name;
- ParseXML(r);
- group.Add(group.Count, this);
- }
- private void ParseXML(XmlReader r)
- {
- Stack<XMLEntry> stack = new Stack<XMLEntry>();
- do
- {
- switch (r.NodeType)
- {
- case XmlNodeType.Element:
- if (r.HasAttributes && r.Name == type)
- {
- for (int i = 0; i < r.AttributeCount; ++i)
- {
- r.MoveToAttribute(i);
- attributes.Add(r.Name, r.Value);
- }
- r.MoveToElement();
- }
- if (r.Name != type)
- {
- if (children.ContainsKey(r.Name))
- children[r.Name].AddGroup(new XMLEntry(r));
- else
- children.Add(r.Name, new XMLEntry(r));
- }
- else
- if (r.IsEmptyElement)
- return;
- break;
- case XmlNodeType.Text:
- this.text = r.Value;
- break;
- case XmlNodeType.EndElement:
- if (r.Name == type)
- return;
- else
- return;
- default:
- break;
- }
- } while (r.Read());
- }
- public void AddGroup(XMLEntry i)
- {
- group.Add(group.Count, i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement