Esempio n. 1
0
        private void ParseTable(ValuationDataPointAggregate aggregate, XParseElement sourceNode, string ticker, string xPath)
        {
            var resultNode = sourceNode;

            if (!(string.IsNullOrWhiteSpace(xPath) || string.IsNullOrEmpty(xPath)))
            {
                resultNode = XPath.GetElement(xPath, sourceNode);
            }
            int                rowNum = 0;
            float              tempVal;
            XPathAttribute     xpath;
            object             value;
            XParseElement      targetNode, description;
            ValuationDataPoint data;
            string             extractVal;

            if (resultNode != null)
            {
                foreach (XParseElement row in resultNode.Elements())
                {
                    if (row.Name.LocalName == "tr")
                    {
                        rowNum++;
                        if (rowNum > 1 && rowNum <= 3) // skip row header
                        {
                            description = XPath.GetElement("/td[1]/font[1]/b", row);
                            if (description != null)
                            {
                                if (description.Value.Contains("Sector"))
                                {
                                    data         = new ValuationDataPoint();
                                    data.Context = ContextType.Sector;
                                    FillDataPoint(data, row);
                                    aggregate.Sector = data;
                                }
                                else if (description.Value.Contains("Industry"))
                                {
                                    data         = new ValuationDataPoint();
                                    data.Context = ContextType.Industry;
                                    FillDataPoint(data, row);
                                    aggregate.Industry = data;
                                }
                            }
                        }
                        else if (rowNum > 3)
                        {
                            description = XPath.GetElement("/td[1]/font/a[2]", row);
                            if (description != null && description.Value == ticker)
                            {
                                data         = new ValuationDataPoint();
                                data.Context = ContextType.Equity;
                                FillDataPoint(data, row);
                                aggregate.Self = data;
                                break;
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private static void FillDataPoint(ValuationDataPoint data, XParseElement node)
        {
            XPathAttribute xpath;
            object         value;
            XParseElement  targetNode;
            string         extractVal;
            string         temp;

            foreach (var property in data.GetType().GetProperties())
            {
                xpath = GetXPathFromAttribute(property, data.Context.ToString());
                if (xpath == null)
                {
                    continue;
                }

                targetNode = XPath.GetElement(xpath.Path, node);

                if (xpath.Source != string.Empty)
                {
                    temp = targetNode.Attribute(new XParseName(xpath.Source)).Value;
                }
                else
                {
                    temp = targetNode.Value;
                }

                if (temp == "NA")
                {
                    continue;
                }

                extractVal = (xpath.RegexExpression != string.Empty) ?
                             MyHelper.ExtractPattern(temp, xpath.RegexExpression).Replace("\r\n", " ") :
                             temp;


                value = Convert.ChangeType(extractVal, property.PropertyType);
                property.SetValue(data, value);
            }
        }