コード例 #1
0
        public static IEnumerable <ParsedProperty> ParsePropertyTable(this HtmlNode tableNode, bool isReadOnly)
        {
            var rows = tableNode.SelectNodes("//tr[td]");

            foreach (var row in rows)
            {
                var cells = row.SelectNodes("td");

                string fieldText = cells[0].InnerText; //l2mtu(integer; Default:
                string fieldName;
                string fieldType;
                string defaultValue;
                ParseFieldText(fieldText, isReadOnly, out fieldName, out fieldType, out defaultValue);
                string description = cells[1].InnerText;
                string propName    = GeneratorHelper.Camelize(fieldName);
                bool   isMandatory = GeneratorHelper.DetermineFieldMandatory(fieldName, string.Empty);

                yield return(new ParsedProperty(propName, fieldName, description, fieldType, isReadOnly, isMandatory, defaultValue));
            }
        }
コード例 #2
0
        private void btnLoadAndResolve_Click(object sender, EventArgs e)
        {
            tbEntityPath.Text   = "";
            tbProperties.Text   = "";
            tbROProperties.Text = "";
            tbDescription.Text  = "";

            HtmlWeb web = new HtmlWeb();

            HtmlAgilityPack.HtmlDocument doc = web.Load(tbWikiUrl.Text);
            //var rootContentDiv = doc.DocumentNode.SelectSingleNode("/html/body/div[@id='content']");
            //var documentationContentNode = rootContentDiv.SelectSingleNode("div[@id='bodyContent']/div[@id='mw-content-text']");

            string entityPath = doc.ParseEntityPath();

            tbEntityPath.Text = entityPath; //entity path from article header
            string entityName = ("blablabla/" + entityPath).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();

            tbDescription.Lines = doc.GetTextOfParagraph("Summary", entityName, entityName + "s", GeneratorHelper.Camelize(entityName), GeneratorHelper.Camelize(entityName + "s")).ToArray(); //description from text of "Summary" paragraph

            var propertiesPara = doc.GetParagraphNode("Properties", "Property Description");                                                                                                   //properties from "Properties" or "Property Description" paragraph

            if (propertiesPara != null)
            {
                var propertiesTable = propertiesPara.GetNextSiblingOfType("table");
                tbProperties.Text = propertiesTable.OuterHtml;
            }

            var roPropertiesPara = doc.GetParagraphNode("Read-only properties", "Read only properties", "Read-only proterties"); // R/O properties from "Read-only properties" or "Read only properties" paragraph

            if (roPropertiesPara != null)
            {
                var roPropertiesTable = roPropertiesPara.GetNextSiblingOfType("table");
                tbROProperties.Text = roPropertiesTable.OuterHtml;
                //var properties = roPropertiesTable.ParsePropertyTable(true).ToArray();
            }
        }