/// <summary> /// Parse the specified bulletNodeElement. /// Read all the data from the xml node into this dude. /// </summary> /// <param name="bulletNodeElement">Bullet node element.</param> public void Parse(XmlNode bulletNodeElement, BulletMLNode parentNode) { // Handle null argument. if (null == bulletNodeElement) { throw new ArgumentNullException("bulletNodeElement"); } //grab the parent node Parent = parentNode; //Parse all our attributes XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes; for (var i = 0; i < mapAttributes.Count; i++) { var strName = mapAttributes.Item(i).Name; var strValue = mapAttributes.Item(i).Value; switch (strName) { //skip the type attribute in top level nodes case "type" when ENodeName.bulletml == Name: continue; //get the bullet node type case "type": NodeType = StringToType(strValue); break; case "label": //label is just a text value Label = strValue; break; } } //parse all the child nodes if (!bulletNodeElement.HasChildNodes) { return; } for (var childNode = bulletNodeElement.FirstChild; null != childNode; childNode = childNode.NextSibling) { switch (childNode.NodeType) { //if the child node is a text node, parse it into this dude case XmlNodeType.Text: //Get the text of the child xml node, but store it in THIS bullet node NodeEquation.Parse(childNode.Value); continue; case XmlNodeType.Comment: //skip any comments in the bulletml script continue; default: //create a new node var childBulletNode = NodeFactory.CreateNode(StringToName(childNode.Name)); //read in the node and store it childBulletNode.Parse(childNode, this); ChildNodes.Add(childBulletNode); break; } } }
/// <summary> /// Parse the specified bulletNodeElement. /// Read all the data from the XML node into this node. /// </summary> /// <param name="bulletNodeElement">Bullet node element.</param> /// <param name="parentNode">Parent node element.</param> public virtual void Parse(XmlNode bulletNodeElement, BulletMLNode parentNode) { // Handle null argument. if (bulletNodeElement == null) { throw new ArgumentNullException(nameof(bulletNodeElement)); } // Grab the parent node Parent = parentNode; // Parse all attributes except for the root node if (Parent != null) { XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes; if (mapAttributes != null) { for (var i = 0; i < mapAttributes.Count; i++) { var strName = mapAttributes.Item(i).Name; var strValue = mapAttributes.Item(i).Value; // Get the bullet node type if (strName == AttributeName.type.ToString()) { NodeType = StringToType(strValue); } // Label is just a text value else if (strName == AttributeName.label.ToString()) { Label = strValue; } } } } // Parse all the child nodes if (bulletNodeElement.HasChildNodes) { for (var childNode = bulletNodeElement.FirstChild; childNode != null; childNode = childNode.NextSibling) { // Skip any comments in the bulletml script if (childNode.NodeType == XmlNodeType.Comment) { continue; } // If the child node is a text node, parse it into this bullet if (childNode.NodeType == XmlNodeType.Text) { // Get the text of the child xml node, but store it in THIS bullet node _nodeEquation.Parse(childNode.Value); continue; } // Create a new node var childBulletNode = NodeFactory.CreateNode(StringToName(childNode.Name)); // Read in the node and store it childBulletNode.Parse(childNode, this); ChildNodes.Add(childBulletNode); } } }