Parse() 공개 메소드

Parse the specified bulletNodeElement. Read all the data from the xml node into this dude.
public Parse ( XmlNode bulletNodeElement, BulletMLNode parentNode ) : bool
bulletNodeElement System.Xml.XmlNode Bullet node element.
parentNode BulletMLNode
리턴 bool
예제 #1
0
        /// <summary>
        /// Parses a bulletml document into this bullet pattern
        /// </summary>
        /// <param name="xmlFileName">Xml file name.</param>
        public bool ParseXML(string xmlFileName)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Ignore;

            using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
            {
                //Open the file.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode rootXmlNode = xmlDoc.DocumentElement;

                //make sure it is actually an xml node
                if (rootXmlNode.NodeType == XmlNodeType.Element)
                {
                    //eat up the name of that xml node
                    string strElementName = rootXmlNode.Name;
                    if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes)
                    {
                        //The first node HAS to be bulletml
                        Debug.Assert(false);
                        return(false);
                    }

                    //Create the root node of the bulletml tree
                    RootNode = new BulletMLNode();

                    //Read in the whole bulletml tree
                    if (!RootNode.Parse(rootXmlNode, null))
                    {
                        //an error ocurred reading in the tree
                        return(false);
                    }
                    Debug.Assert(ENodeName.bulletml == RootNode.Name);

                    //Find what kind of pattern this is: horizontal or vertical
                    XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                    for (int i = 0; i < mapAttributes.Count; i++)
                    {
                        //will only have the name attribute
                        string strName  = mapAttributes.Item(i).Name;
                        string strValue = mapAttributes.Item(i).Value;
                        if ("type" == strName)
                        {
                            //if  this is a top level node, "type" will be veritcal or horizontal
                            Orientation = StringToPatternType(strValue);
                        }
                    }
                }
                else
                {
                    //should be an xml node!!!
                    Debug.Assert(false);
                    return(false);
                }
            }

            //grab that filename
            Filename = xmlFileName;
            return(true);
        }
예제 #2
0
        /// <summary>
        /// Parses a bulletml document into this bullet pattern
        /// </summary>
        /// <param name="xmlFileName">Xml file name.</param>
        public bool ParseXML(string xmlFileName)
        {
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.DtdProcessing = DtdProcessing.Ignore;

            using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
            {
                //Open the file.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode rootXmlNode = xmlDoc.DocumentElement;

                //make sure it is actually an xml node
                if (rootXmlNode.NodeType == XmlNodeType.Element)
                {
                    //eat up the name of that xml node
                    string strElementName = rootXmlNode.Name;
                    if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes)
                    {
                        //The first node HAS to be bulletml
                        Debug.Assert(false);
                        return false;
                    }

                    //Create the root node of the bulletml tree
                    RootNode = new BulletMLNode();

                    //Read in the whole bulletml tree
                    if (!RootNode.Parse(rootXmlNode, null))
                    {
                        //an error ocurred reading in the tree
                        return false;
                    }
                    Debug.Assert(ENodeName.bulletml == RootNode.Name);

                    //Find what kind of pattern this is: horizontal or vertical
                    XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                    for (int i = 0; i < mapAttributes.Count; i++)
                    {
                        //will only have the name attribute
                        string strName = mapAttributes.Item(i).Name;
                        string strValue = mapAttributes.Item(i).Value;
                        if ("type" == strName)
                        {
                            //if  this is a top level node, "type" will be veritcal or horizontal
                            Orientation = StringToPatternType(strValue);
                        }
                    }
                }
                else
                {
                    //should be an xml node!!!
                    Debug.Assert(false);
                    return false;
                }
            }

            //grab that filename
            Filename = xmlFileName;
            return true;
        }
예제 #3
0
        /// <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 bool Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            Debug.Assert(null != bulletNodeElement);

            //grab the parent node
            Parent = parentNode;

            //get the node type
            Name = BulletMLNode.StringToName(bulletNodeElement.Name);

            //Parse all our attributes
            XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;

            for (int i = 0; i < mapAttributes.Count; i++)
            {
                string strName  = mapAttributes.Item(i).Name;
                string strValue = mapAttributes.Item(i).Value;

                if ("type" == strName)
                {
                    //skip the type attribute in top level nodes
                    if (ENodeName.bulletml == Name)
                    {
                        continue;
                    }

                    //get the bullet node type
                    NodeType = BulletMLNode.StringToType(strValue);
                }
                else if ("label" == strName)
                {
                    //label is just a text value
                    Label = strValue;
                }
            }

            //parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (XmlNode childNode = bulletNodeElement.FirstChild;
                     null != childNode;
                     childNode = childNode.NextSibling)
                {
                    //if the child node is a text node, parse it into this dude
                    if (XmlNodeType.Text == childNode.NodeType)
                    {
                        //Get the text of the child xml node, but store it in THIS bullet node
                        NodeEquation.Parse(childNode.Value);
                        continue;
                    }

                    //create a new node
                    BulletMLNode childBulletNode = new BulletMLNode();

                    //read in the node
                    if (!childBulletNode.Parse(childNode, this))
                    {
                        return(false);
                    }

                    //store the node
                    ChildNodes.Add(childBulletNode);
                }
            }

            return(true);
        }
예제 #4
0
        /// <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 bool Parse(XmlNode bulletNodeElement, BulletMLNode parentNode)
        {
            Debug.Assert(null != bulletNodeElement);

            //grab the parent node
            Parent = parentNode;

            //get the node type
            Name = BulletMLNode.StringToName(bulletNodeElement.Name);

            //Parse all our attributes
            XmlNamedNodeMap mapAttributes = bulletNodeElement.Attributes;
            for (int i = 0; i < mapAttributes.Count; i++)
            {
                string strName = mapAttributes.Item(i).Name;
                string strValue = mapAttributes.Item(i).Value;

                if ("type" == strName)
                {
                    //skip the type attribute in top level nodes
                    if (ENodeName.bulletml == Name)
                    {
                        continue;
                    }

                    //get the bullet node type
                    NodeType = BulletMLNode.StringToType(strValue);
                }
                else if ("label" == strName)
                {
                    //label is just a text value
                    Label = strValue;
                }
            }

            //parse all the child nodes
            if (bulletNodeElement.HasChildNodes)
            {
                for (XmlNode childNode = bulletNodeElement.FirstChild;
                         null != childNode;
                         childNode = childNode.NextSibling)
                {
                    //if the child node is a text node, parse it into this dude
                    if (XmlNodeType.Text == childNode.NodeType)
                    {
                        //Get the text of the child xml node, but store it in THIS bullet node
                        NodeEquation.Parse(childNode.Value);
                        continue;
                    }

                    //create a new node
                    BulletMLNode childBulletNode = new BulletMLNode();

                    //read in the node
                    if (!childBulletNode.Parse(childNode, this))
                    {
                        return false;
                    }

                    //store the node
                    ChildNodes.Add(childBulletNode);
                }
            }

            return true;
        }