public string ChildElementText(string name) { string returnValue = ""; XmlSimpleElement element = FindChildElement(name); if (element != null) { returnValue = element.Text; } return(returnValue); }
public int ChildElementTextAsInt(string name) { int returnValue = 0; XmlSimpleElement element = FindChildElement(name); if (element != null) { returnValue = element.TextAsInt; } return(returnValue); }
public void Add(XmlSimpleElement se) { this.List.Add(se); }
public XmlSimpleElement Parse(XmlTextReader reader) { XmlSimpleElement se = null; this.Reader = reader; while (!Reader.EOF) { Reader.Read(); switch (Reader.NodeType) { case XmlNodeType.Element: // create a new SimpleElement se = new XmlSimpleElement(Reader.LocalName); currentElement = se; if (elements.Count == 0) { rootElement = se; elements.Push(se); } else { XmlSimpleElement parent = (XmlSimpleElement)elements.Peek(); parent.ChildElements.Add(se); // don't push empty elements onto the stack //if (Reader.IsEmptyElement) // ends with "/>" // break; //else // elements.Push(se); if (!Reader.IsEmptyElement) { elements.Push(se); } } if (Reader.HasAttributes) { while (Reader.MoveToNextAttribute()) { currentElement.setAttribute(Reader.Name, Reader.Value); } } break; case XmlNodeType.Attribute: se.setAttribute(Reader.Name, Reader.Value); break; case XmlNodeType.EndElement: //pop the top element elements.Pop(); break; case XmlNodeType.Text: currentElement.Text = Reader.Value; break; case XmlNodeType.CDATA: currentElement.Text = Reader.Value; break; default: // ignore break; } } return(rootElement); }
public XmlParser() { elements = new Stack(); currentElement = null; }