private void CheckImageAlt(CHtmlDocument doc, CHtmlNodeCollection nodes) { foreach (CHtmlNode node in nodes) { if (node is CHtmlElement) { CHtmlElement element = node as CHtmlElement; if ("img".Equals(element.Name.ToLower(), StringComparison.OrdinalIgnoreCase)) { if (element.Attributes.HasAttribute("alt") == false) { // 리포터 모듈 작성 할것 AddReportItem(doc.HRef, element.HTML, "[" + 1001 + "] img태그에 Alt가 없습니다."); } if (element.Attributes.HasAttribute("height") == false) { AddReportItem(doc.HRef, element.HTML, "[" + 1002 + "] img태그에 Height속성이 없습니다."); } if (element.Attributes.HasAttribute("width") == false) { AddReportItem(doc.HRef, element.HTML, "[" + 1003 + "] img태그에 Width속성이 없습니다."); } } if (element.Nodes.Count > 0) { CheckImageAlt(doc, element.Nodes); } } } }
///////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="nodes"></param> /// <param name="result"></param> /// <param name="searchChildren"></param> public void SearchMatching(CHtmlNodeCollection nodes, CHtmlNodeCollection result, bool searchChildren) { System.Diagnostics.Debug.Assert(nodes != null); System.Diagnostics.Debug.Assert(result != null); for (int index = 0, count = nodes.Count; index < count; ++index) { CHtmlElement element = nodes[index] as CHtmlElement; if (element != null) { if (IsMatching(element) == true) { result.Add(element); } if (searchChildren == true && element.Nodes.Count != 0) { SearchMatching(element.Nodes, result, searchChildren); } } } }
///////////////////////////////////////////////////////////////////////////////// #region ¤ñ¹ï¾Þ? ///////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="element"></param> /// <returns></returns> public bool IsMatching(CHtmlElement element) { System.Diagnostics.Debug.Assert(element != null); System.Diagnostics.Debug.Assert(m_simpleSelectorList.Count > 0); bool result = false; DCssSimpleSelector.Relation combinator = DCssSimpleSelector.Relation.Descendant; int index = m_simpleSelectorList.Count - 1; DCssSimpleSelector simpleSelector = m_simpleSelectorList[index]; if (simpleSelector.IsMatching(element) == true) // first matching { --index; if (index >= 0) { simpleSelector = m_simpleSelectorList[index]; combinator = simpleSelector.Combinator; switch (combinator) { case DCssSimpleSelector.Relation.Child: case DCssSimpleSelector.Relation.Descendant: element = element.Parent; // child to parent break; case DCssSimpleSelector.Relation.Sibling: element = element.PreviousSibling as CHtmlElement; // brother break; default: System.Diagnostics.Debug.Assert(false); break; } } while (index >= 0 && element != null) { simpleSelector = m_simpleSelectorList[index]; if (simpleSelector.IsMatching(element) == true) // simple selector matching { --index; // match next simple selector if (index >= 0) { combinator = simpleSelector.Combinator; switch (combinator) { case DCssSimpleSelector.Relation.Child: case DCssSimpleSelector.Relation.Descendant: element = element.Parent; // child to parent break; case DCssSimpleSelector.Relation.Sibling: element = element.PreviousSibling as CHtmlElement; // brother break; default: System.Diagnostics.Debug.Assert(false); break; } } } else { if (combinator == DCssSimpleSelector.Relation.Descendant) { element = element.Parent;// child to parent } else if (combinator == DCssSimpleSelector.Relation.Child || combinator == DCssSimpleSelector.Relation.Sibling) { break; } else { System.Diagnostics.Debug.Assert(false); } } } if (index == -1) { result = true; } } return(result); }
///////////////////////////////////////////////////////////////////////////// /// <summary> /// /// </summary> /// <param name="element"></param> /// <returns></returns> public bool IsMatching(CHtmlElement element) { System.Diagnostics.Debug.Assert(element != null); // id if (m_id.Length != 0) { CHtmlAttribute attribute = element.Attributes["id"]; if (attribute == null || m_id.Equals(attribute.Value) == false) // match ID { return(false); } } // class if (m_class.Length != 0) { CHtmlAttribute attribute = element.Attributes["class"]; if (attribute == null || m_class.Equals(attribute.Value) == false) // match class { return(false); } } // element name if ((m_elementNames.Length != 0 && m_elementNames.Equals("*") == false) && m_elementNames.Equals(element.Name) == false) // match tag { return(false); } // attribute switch (m_attributeMatchingType) { case AttributeMatching.None: break; case AttributeMatching.ExactlyEqualName: // E[foo] if (m_attributeName.Equals("") == false) { int attributeIndex = element.Attributes.IndexOf(m_attributeName); if (attributeIndex == -1) { return(false); } } break; case AttributeMatching.ExactlyEqualValue: // E[foo="warning"] if (m_attributeName.Equals("") == false) { int attributeIndex = element.Attributes.IndexOf(m_attributeName); if (attributeIndex == -1 || element.Attributes[attributeIndex].Value.Equals(m_attributeValue) == false) { return(false); } } break; case AttributeMatching.IncludesValue: // E[foo~="warning"] if (m_attributeName.Equals("") == false) { int attributeIndex = element.Attributes.IndexOf(m_attributeName); if (attributeIndex == -1 || element.Attributes[attributeIndex].Value.IndexOf(m_attributeValue) == -1) { return(false); } } break; case AttributeMatching.BeginValue: // E[lang|="en"] if (m_attributeName.Equals("") == false) { int attributeIndex = element.Attributes.IndexOf(m_attributeName); if (attributeIndex == -1 || element.Attributes[attributeIndex].Value.IndexOf(m_attributeValue) != 0) { return(false); } } break; default: System.Diagnostics.Debug.Assert(false); break; } return(true); }