/// <summary> /// Finds the first match for the type, and must match the attributes if they're specified. Option to disable recursive search will only search on the next level if set to false. /// </summary> /// <param name="type"></param> /// <param name="attributes"></param> /// <returns></returns> public HtmlItem Get(string type, Dictionary <string, string> attributes = null, bool continueUp = false, bool recursive = true) { //look through children HtmlItem i; if ((i = get(type, attributes, recursive)) != null) { return(i); } //if we can continue up if (continueUp) { HtmlItem n = next(); if (n != null) { //first check if it matches if (n.IsType(type) && n.HasAttributes(attributes)) { return(n); } return(n.Get(type, attributes, continueUp, recursive)); } } return(null); }
/// <summary> /// Processes all the instructions. Returns null if failed to grab it. /// </summary> /// <returns></returns> public string Get(HtmlItem item) { switch (Instruction) { case InstructionType.GetAnyItem: case InstructionType.GetNextItem: //if there's no next instruction, there was an error if (Next == null) { return(null); } //if we get any item, we search as far down as necessary. Otherwise we just search one level HtmlItem nextItem = item.Get(Type, AttributesToMatch, false, Instruction == InstructionType.GetAnyItem); if (nextItem == null) { return(null); } return(Next.Get(nextItem)); case InstructionType.GetAttributeValue: string answer; if (item.Attributes.TryGetValue(AttributeToFetch, out answer)) { return(answer); } return(null); case InstructionType.GetValue: return(item.GetText()); case InstructionType.GetImmediateValue: return(item.GetImmediateText()); case InstructionType.Start: if (Next == null) { return(null); } return(Next.Get(item)); } return(null); }