/////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 속성명에 해당하는 속성노드 반환
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CHtmlAttributeCollection FindByName(string name)
        {
            System.Diagnostics.Debug.Assert(name != null);

            name = name.ToLower();

            CHtmlAttributeCollection result = new CHtmlAttributeCollection();

            FindByName(name, result);
            return(result);
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="result"></param>
        public void FindByNameValue(string name, string value, CHtmlAttributeCollection result)
        {
            System.Diagnostics.Debug.Assert(name != null);
            System.Diagnostics.Debug.Assert(result != null);

            name = name.ToLower();
            for (int index = 0, count = m_attributeList.Count; index < count; ++index)
            {
                CHtmlAttribute attribute = m_attributeList[index];
                if (attribute.Name.Equals(name) && attribute.Value.Equals(value))
                {
                    result.Add(attribute);
                }
            }
        }
Ejemplo n.º 3
0
        /////////////////////////////////////////////////////////////////////////////////
        #region

        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        ///
        /// </summary>
        /// <param name="htmlStream"></param>
        /// <returns></returns>
        private Encoding DetectCharset(CHtmlNodeCollection nodes)
        {
            Encoding result = null;

            string charset = "";

            CHtmlNodeCollection metaNodes = new CHtmlNodeCollection();
            CHtmlElement        node      = nodes["html"] as CHtmlElement;

            if (node != null)
            {
                node = node.Nodes["head"] as CHtmlElement;
            }
            if (node != null)
            {
                node.Nodes.FindByNameAttribute(metaNodes, "meta", "content", false);
            }

            for (int nodeIndex = 0, count = metaNodes.Count; nodeIndex < count; ++nodeIndex)
            {
                CHtmlElement metaElement = metaNodes[nodeIndex] as CHtmlElement;
                if (metaElement != null)
                {
                    int index = -1;
                    CHtmlAttributeCollection attributes = metaElement.Attributes.FindByName("content");
                    for (int attributeIndex = 0, attributeCount = attributes.Count; attributeIndex < attributeCount; ++attributeIndex)
                    {
                        CHtmlAttribute attribute = attributes[attributeIndex];
                        if ((index = attribute.Value.IndexOf("charset")) != -1)
                        {
                            string value      = attribute.Value;
                            int    startIndex = index + 7;
                            while (startIndex < value.Length && CHtmlUtil.EqualesOfAnyChar(value[startIndex], " ="))
                            {
                                ++startIndex;
                            }
                            int endIndex = startIndex + 1;
                            while (endIndex < value.Length && !CHtmlUtil.EqualesOfAnyChar(value[endIndex], " "))
                            {
                                ++endIndex;
                            }

                            if (startIndex < value.Length && endIndex - startIndex > 0)
                            {
                                charset = value.Substring(startIndex, endIndex - startIndex);
                                try
                                {
                                    result = Encoding.GetEncoding(charset);
                                    break;
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="token"></param>
        /// <param name="attributeCollection"></param>
        private void ResolveAttribute(ref int visitor, CHtmlAttributeCollection attributeCollection)
        {
            Token token = m_tokens[visitor];

            // read the attributes and values
            while(token.Type != Token.TokenType.TagEnd && token.Type != Token.TokenType.TagCloseEnd)
            {
                System.Diagnostics.Debug.Assert(token.Type == Token.TokenType.AttributeName);
                string attribute_name = token.Content;
                ++visitor;
                token = m_tokens[visitor];
                if(token.Type == Token.TokenType.AttributeValue)
                {
                    string attribute_value = CHtmlUtil.TranHtmlTextToStr(token.Content);
                    CHtmlAttribute attribute = new CHtmlAttribute(attribute_name, attribute_value);
                    attributeCollection.Add(attribute);
                    ++visitor;
                }
                else
                {
                    // Null-value attribute
                    CHtmlAttribute attribute = new CHtmlAttribute(attribute_name);
                    attributeCollection.Add(attribute);
                }

                token = m_tokens[visitor];
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <param name="result"></param>
        public void FindByNameValue(string name, string value, CHtmlAttributeCollection result)
        {
            System.Diagnostics.Debug.Assert(name != null);
            System.Diagnostics.Debug.Assert(result != null);

            name = name.ToLower();
            for(int index = 0, count = m_attributeList.Count; index < count; ++index)
            {
                CHtmlAttribute attribute = m_attributeList[index];
                if(attribute.Name.Equals(name) && attribute.Value.Equals(value))
                    result.Add(attribute);
            }
        }
        /////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// �Ӽ���� �ش��ϴ� �Ӽ���� ��ȯ
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public CHtmlAttributeCollection FindByName(string name)
        {
            System.Diagnostics.Debug.Assert(name != null);

            name = name.ToLower();

            CHtmlAttributeCollection result = new CHtmlAttributeCollection();
            FindByName(name, result);
            return result;
        }