tag
public class tag
{
public string name;
public string id;
public tagType type;
public Dictionary<String, String> attributes;
public List<string> contents;
public List<tag> tagChildren;
public string stringFormat;
public string content;
public int depth;
public tag() { }
public tag( string initialtag )
{
type = (initialtag.IndexOf("/")>=0) ? tagType.close : tagType.open;
depth = 0;
instantiateParameters();
PopulateAttributes(initialtag.Replace("/", ""));
}
public tag(string initialtag, int d)
{
type = (initialtag.IndexOf("/") >= 0) ? tagType.close : tagType.open;
depth = d;
instantiateParameters();
PopulateAttributes(initialtag.Replace("/", ""));
}
private void instantiateParameters()
{
attributes = new Dictionary<String, String>();
contents = new List<string>();
stringFormat = "";
tagChildren = new List<tag>();
}
private void PopulateAttributes(string tagItem)
{
int firstSpace = tagItem.IndexOf(" ");
bool haveAttributes = firstSpace > -1;
string name = tagItem;
string[] potAttr;
string key;
string value;
if( haveAttributes )
{
name = tagItem.Substring(0, firstSpace);
potAttr = tagItem.Substring(firstSpace).Split(' ');
foreach( string attr in potAttr)
{
if (attr != "")
{
key = attr.Split('=')[0];
value = attr.Split('=')[1];
attributes.Add(key, value);
}
}
}
this.name = name;
}
}