void Text(string content) { OnText?.Invoke(content); }
public void Parse() { try { reader.MoveToContent(); while (reader.Read()) { var arg = new ParseEventArg { NodeType = reader.NodeType, Depth = reader.Depth, Name = reader.Name, EmptyElement = reader.IsEmptyElement }; if (reader.HasValue) { arg.Value = reader.Value; } else { arg.Value = null; } if (reader.HasAttributes) { var arr = new Attribute[reader.AttributeCount]; for (var i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); arr[i] = new Attribute { Name = reader.Name, Value = reader.Value, Index = i }; } reader.MoveToElement(); arg.Attributes = new ReadOnlyCollection <Attribute>(arr); } else { arg.Attributes = new ReadOnlyCollection <Attribute>(empty); } OnNode?.Invoke(this, arg); switch (reader.NodeType) { case XmlNodeType.Element: OnElement?.Invoke(this, arg); break; case XmlNodeType.CDATA: OnCData?.Invoke(this, arg); break; case XmlNodeType.Comment: OnComment?.Invoke(this, arg); break; case XmlNodeType.DocumentType: OnDocType?.Invoke(this, arg); break; case XmlNodeType.EndElement: OnEndElement?.Invoke(this, arg); break; case XmlNodeType.EntityReference: OnEntityReferenceUnresolved?.Invoke(this, arg); reader.ResolveEntity(); reader.Read(); arg.Name = reader.Name; arg.Value = reader.Value; arg.Depth = reader.Depth; arg.NodeType = reader.NodeType; OnEntityReference?.Invoke(this, arg); break; case XmlNodeType.ProcessingInstruction: OnProcessingInstruction?.Invoke(this, arg); break; case XmlNodeType.Text: OnText?.Invoke(this, arg); break; } } } catch (XmlException e) { OnException?.Invoke(this, e); } }