void Parse(string aSource)
{
XML lastOpenNode = null;
sNodeStack.Clear();
XMLIterator.Begin(aSource);
while (XMLIterator.NextTag())
{
if (XMLIterator.tagType == XMLTagType.Start || XMLIterator.tagType == XMLTagType.Void)
{
XML childNode;
if (lastOpenNode != null)
childNode = new XML();
else
{
if (this.name != null)
{
Cleanup();
throw new Exception("Invalid xml format - no root node.");
}
childNode = this;
}
childNode.name = XMLIterator.tagName;
childNode._attributes = XMLIterator.GetAttributes(childNode._attributes);
if (lastOpenNode != null)
{
if (XMLIterator.tagType != XMLTagType.Void)
sNodeStack.Push(lastOpenNode);
if (lastOpenNode._children == null)
lastOpenNode._children = new XMLList();
lastOpenNode._children.Add(childNode);
}
if (XMLIterator.tagType != XMLTagType.Void)
lastOpenNode = childNode;
}
else if (XMLIterator.tagType == XMLTagType.End)
{
if (lastOpenNode == null || lastOpenNode.name != XMLIterator.tagName)
{
Cleanup();
throw new Exception("Invalid xml format - <" + XMLIterator.tagName + "> dismatched.");
}
if (lastOpenNode._children == null || lastOpenNode._children.Count == 0)
{
lastOpenNode.text = XMLIterator.GetText();
}
if (sNodeStack.Count > 0)
lastOpenNode = sNodeStack.Pop();
else
lastOpenNode = null;
}
}
}