Inheritance: System.Attribute
Ejemplo n.º 1
0
        public ScraperNode(XmlNode xmlNode, InternalScriptSettings settings)
        {
            this.xmlNode        = xmlNode;
            children            = new List <ScraperNode>();
            this.ScriptSettings = settings;
            loadSuccess         = loadChildren();

            // try to load our node attrbute
            foreach (Attribute currAttr in this.GetType().GetCustomAttributes(true))
            {
                if (currAttr is ScraperNodeAttribute)
                {
                    nodeSettings = (ScraperNodeAttribute)currAttr;
                    continue;
                }
            }

            if (nodeSettings.LoadNameAttribute)
            {
                // Load attributes
                foreach (XmlAttribute attr in xmlNode.Attributes)
                {
                    switch (attr.Name)
                    {
                    case "name":
                        name = attr.Value;
                        break;
                    }
                }

                // Validate NAME attribute
                if (name == null)
                {
                    logger.Error("Missing NAME attribute on: " + xmlNode.OuterXml);
                    loadSuccess = false;
                    return;
                }

                // if it's a bad variable name we fail as well
                if (Name.Contains(" "))
                {
                    logger.Error("Invalid NAME attribute (no spaces allowed) \"" + Name + "\" for " + xmlNode.OuterXml);
                    loadSuccess = false;
                    return;
                }
            }
        }
Ejemplo n.º 2
0
        public ScraperNode(XmlNode xmlNode, ScriptableScraper context)
        {
            this.xmlNode = xmlNode;
            children = new List<ScraperNode>();
            this.Context = context;
            loadSuccess = loadChildren();

            // try to load our node attrbute
            foreach(Attribute currAttr in this.GetType().GetCustomAttributes(true))
                if (currAttr is ScraperNodeAttribute) {
                    nodeSettings = (ScraperNodeAttribute) currAttr;
                    continue;
                }

            if (nodeSettings.LoadNameAttribute) {

                // Load attributes
                foreach (XmlAttribute attr in xmlNode.Attributes) {
                    switch (attr.Name) {
                        case "name":
                            name = attr.Value;
                            break;
                    }
                }

               // Validate NAME attribute
                if (name == null) {
                    logger.Error("Missing NAME attribute on: " + xmlNode.OuterXml);
                    loadSuccess = false;
                    return;
                }

                // if it's a bad variable name we fail as well
                if (Name.Contains(" ")) {
                    logger.Error("Invalid NAME attribute (no spaces allowed) \"" + Name + "\" for " + xmlNode.OuterXml);
                    loadSuccess = false;
                    return;
                }
            }
        }