Пример #1
0
        internal HtmlNode SelectSingleNode(string xpath, System.Xml.Xsl.XsltContext additionalContext)
        {
            Debug.Assert(m_XmlNode != null);

            Debug.Assert(xpath != null);
            if (xpath == null)
            {
                throw new ArgumentNullException("xpath");
            }

            //TODO: The XPATH is mixes case because if not some XPath functions will not work
            //      May be we need an XPathExpression parser, which will only change the
            //      case of the elements and attribute names !!! Will be very cool.
            XmlNode result = m_XmlNode.SelectSingleNode(xpath, XPath.HtmlXsltContext.GetInstance(additionalContext));

            if (result == null || (!(result is XmlRefElement) && !(result is XmlRefAttribute)))
            {
                return(null);
            }
            else
            {
                IHtmlNodeReferenceHolder resRef = result as IHtmlNodeReferenceHolder;
                if (resRef != null)
                {
                    return(resRef.HtmlNodeReference);
                }

                Debug.Assert(false);
                throw new XPathException("The type returned by an XPath operation was unexpected!");
            }
        }
Пример #2
0
            internal bool RemoveAttribute(string attName)
            {
                XmlAttribute             xmlAtt    = ParentNode.m_XmlNode.Attributes[attName];
                IHtmlNodeReferenceHolder refHolder = xmlAtt as IHtmlNodeReferenceHolder;

                if (xmlAtt != null &&
                    refHolder != null)
                {
                    ParentNode.m_XmlNode.Attributes.Remove(xmlAtt);
                    m_HtmlAttList.Remove((HtmlAttribute)refHolder.HtmlNodeReference);

                    ParentNode.OwnerDocument.m_FixupManager.AddOrUpdateFixUp(FixupType.Remove, refHolder.HtmlNodeReference, xmlAtt.Value);

                    return(true);
                }

                return(false);
            }
Пример #3
0
            internal HtmlAttribute this[string attributeName]
            {
                get
                {
                    if (ParentNode == null)
                    {
                        throw new InvalidOperationException("No parent has been set.");
                    }

                    if (ParentNode.m_XmlNode.Attributes == null)
                    {
                        return(null);
                    }

                    // First try the same case
                    XmlAttribute att = ParentNode.m_XmlNode.Attributes[attributeName];
                    if (att == null)
                    {
                        foreach (XmlAttribute attTest in ParentNode.m_XmlNode.Attributes)
                        {
                            if (attTest.Name.Equals(attributeName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                att = attTest;
                                break;
                            }
                        }
                    }

                    IHtmlNodeReferenceHolder attNodeRef = att as IHtmlNodeReferenceHolder;
                    if (att != null)
                    {
                        HtmlNode attNode = attNodeRef.HtmlNodeReference;

                        Debug.Assert(attNode is HtmlAttribute);
                        return(attNode as HtmlAttribute);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
Пример #4
0
        internal HtmlNodeList(XmlNodeList nodeList)
        {
            Debug.Assert(nodeList != null);

            m_List = new List <HtmlNode>();

            foreach (XmlNode node in nodeList)
            {
                IHtmlNodeReferenceHolder nodeRef = node as IHtmlNodeReferenceHolder;

                if (nodeRef != null)
                {
                    m_List.Add(nodeRef.HtmlNodeReference);
                }
                else
                {
                    throw new HtmlParserException("Unexpected node type!");
                }
            }
        }