当前位置: 首页>>代码示例>>C#>>正文


C# Element.AbsUrl方法代码示例

本文整理汇总了C#中Element.AbsUrl方法的典型用法代码示例。如果您正苦于以下问题:C# Element.AbsUrl方法的具体用法?C# Element.AbsUrl怎么用?C# Element.AbsUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Element的用法示例。


在下文中一共展示了Element.AbsUrl方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: handlesBaseUri

        public void handlesBaseUri()
        {
            Tag tag = Tag.ValueOf("a");
            Attributes attribs = new Attributes();
            attribs.Add("relHref", "/foo");
            attribs.Add("absHref", "http://bar/qux");

            Element noBase = new Element(tag, "", attribs);
            Assert.AreEqual("", noBase.AbsUrl("relHref")); // with no base, should NOT fallback to href attrib, whatever it is
            Assert.AreEqual("http://bar/qux", noBase.AbsUrl("absHref")); // no base but valid attrib, return attrib

            Element withBase = new Element(tag, "http://foo/", attribs);
            Assert.AreEqual("http://foo/foo", withBase.AbsUrl("relHref")); // construct abs from base + rel
            Assert.AreEqual("http://bar/qux", withBase.AbsUrl("absHref")); // href is abs, so returns that
            Assert.AreEqual("", withBase.AbsUrl("noval"));

            Element dodgyBase = new Element(tag, "wtf://no-such-protocol/", attribs);
            Assert.AreEqual("http://bar/qux", dodgyBase.AbsUrl("absHref")); // base fails, but href good, so get that
            Assert.AreEqual("", dodgyBase.AbsUrl("relHref")); // base fails, only rel href, so return nothing 
        }
开发者ID:fengweijp,项目名称:NSoup,代码行数:20,代码来源:NodeTest.cs

示例2: TestValidProtocol

        private bool TestValidProtocol(Element el, NSoup.Nodes.Attribute attr, HashSet<Protocol> protocols)
        {
            // try to resolve relative urls to abs, and optionally update the attribute so output html has abs.
            // rels without a baseuri get removed
            string value = el.AbsUrl(attr.Key);
            if (value.Length == 0)
            {
                value = attr.Value; // if it could not be made abs, run as-is to allow custom unknown protocols
            }
            if (!_preserveRelativeLinks)
            {
                attr.Value = value;
            }

            foreach (Protocol protocol in protocols)
            {
                string prot = protocol.ToString() + ":";
                if (value.ToLowerInvariant().StartsWith(prot))
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:fengweijp,项目名称:NSoup,代码行数:24,代码来源:Whitelist.cs

示例3: MaybeSetBaseUri

        public void MaybeSetBaseUri(Element baseEl)
        {
            if (_baseUriSetFromDoc) // only listen to the first <base href> in parse
            {
                return;
            }

            string href = baseEl.AbsUrl("href");
            if (href.Length != 0)
            { // ignore <base target> etc
                _baseUri = href;
                _baseUriSetFromDoc = true;
                _doc.BaseUri = href; // set on the doc so doc.createElement(Tag) will get updated base, and to update all descendants
            }
        }
开发者ID:fengweijp,项目名称:NSoup,代码行数:15,代码来源:HtmlTreeBuilder.cs


注:本文中的Element.AbsUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。