示例#1
0
        String IMarkupFormatter.Attribute(IAttr attr)
        {
            var namespaceUri = attr.NamespaceUri;
            var localName = attr.LocalName;
            var value = attr.Value;
            var temp = Pool.NewStringBuilder();

            if (String.IsNullOrEmpty(namespaceUri))
                temp.Append(localName);
            else if (namespaceUri == Namespaces.XmlUri)
                temp.Append(Namespaces.XmlPrefix).Append(Symbols.Colon).Append(localName);
            else if (namespaceUri == Namespaces.XLinkUri)
                temp.Append(Namespaces.XLinkPrefix).Append(Symbols.Colon).Append(localName);
            else if (namespaceUri == Namespaces.XmlNsUri)
                temp.Append(XmlNamespaceLocalName(localName));
            else
                temp.Append(attr.Name);

            temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);

            for (int i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                    case Symbols.Ampersand: temp.Append("&amp;"); break;
                    case Symbols.NoBreakSpace: temp.Append("&nbsp;"); break;
                    case Symbols.DoubleQuote: temp.Append("&quot;"); break;
                    default: temp.Append(value[i]); break;
                }
            }

            return temp.Append(Symbols.DoubleQuote).ToPool();
        }
示例#2
0
        public IAttr SetNamedItem(IAttr item)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var name = item.Name;

                for (int i = 0; i < _items.Count; i++)
                {
                    if (name.Is(_items[i].Name))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;
                        RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        return(attr);
                    }
                }

                _items.Add(proposed);
                RaiseChangedEvent(proposed, proposed.Value, null);
            }

            return(null);
        }
示例#3
0
        public IAttr SetNamedItemWithNamespaceUri(IAttr item)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var localName    = item.LocalName;
                var namespaceUri = item.NamespaceUri;

                for (int i = 0; i < _items.Count; i++)
                {
                    if (localName.Is(_items[i].LocalName) && namespaceUri.Is(_items[i].NamespaceUri))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;
                        RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        return(attr);
                    }
                }

                _items.Add(proposed);
                RaiseChangedEvent(proposed, proposed.Value, null);
            }

            return(null);
        }
示例#4
0
        public IAttr SetNamedItemWithNamespaceUri(IAttr item)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var localName    = item.LocalName;
                var namespaceUri = item.NamespaceUri;

                for (int i = 0; i < _items.Count; i++)
                {
                    if (String.Equals(_items[i].LocalName, localName, StringComparison.Ordinal) &&
                        String.Equals(_items[i].NamespaceUri, namespaceUri, StringComparison.Ordinal))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;
                        RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        return(attr);
                    }
                }

                _items.Add(proposed);
                RaiseChangedEvent(proposed, proposed.Value, null);
            }

            return(null);
        }
示例#5
0
        /// <summary>
        /// Check if the value is a integer
        /// </summary>
        /// <param name="attr"></param>
        /// <returns></returns>
        public static bool IsValueInt(this IAttr attr)
        {
            int  value = 0;
            bool isInt = int.TryParse(attr.Value, out value);

            return(isInt);
        }
        internal static void WriteAttributeName(IAttr attr, StringBuilder stringBuilder)
        {
            var namespaceUri = attr.NamespaceUri;
            var localName    = attr.LocalName;

            if (String.IsNullOrEmpty(namespaceUri))
            {
                stringBuilder.Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XmlUri))
            {
                stringBuilder.Append(NamespaceNames.XmlPrefix).Append(Symbols.Colon).Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XLinkUri))
            {
                stringBuilder.Append(NamespaceNames.XLinkPrefix).Append(Symbols.Colon).Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XmlNsUri))
            {
                stringBuilder.Append(XmlNamespaceLocalName(localName));
            }
            else
            {
                stringBuilder.Append(attr.Name);
            }
        }
示例#7
0
        public void Deserialize(IAttr attr, StreamWriter streamWriter)
        {
            IAttrContainer container = (attr as Attr <AttrContainer>).Value;

            streamWriter.WriteLine($"{{{attr.Name}:{attr.Type}:}}");
            Deserialize(container, streamWriter);
            streamWriter.WriteLine($"}}");
        }
 public static String GetAbsUrl(this IAttr attr, string origin)
 {
     try
     {
         return(new Uri(new Uri(origin), attr.Value).ToString());
     }
     catch
     {
         return(attr.Value);
     }
 }
示例#9
0
 /// <summary>
 /// Checks if the attribute name starts with a string
 /// </summary>
 /// <param name="attr"></param>
 /// <param name="strData"></param>
 /// <returns></returns>
 public static bool NameStartsWith(this IAttr attr, string startString, bool ignoreCase = false)
 {
     if (ignoreCase)
     {
         return(attr.Name.StartsWith(startString, StringComparison.InvariantCultureIgnoreCase));
     }
     else
     {
         return(attr.Name.StartsWith(startString));
     }
 }
示例#10
0
        /// <summary>
        /// Removes an attribute from the document.
        /// </summary>
        /// <param name="tag">Tag the attribute belongs to</param>
        /// <param name="attribute">Attribute to be removed</param>
        /// <param name="reason">Reason for removal</param>
        private void RemoveAttribute(IElement tag, IAttr attribute, RemoveReason reason)
        {
            var e = new RemovingAttributeEventArgs {
                Tag = tag, Attribute = attribute, Reason = reason
            };

            OnRemovingAttribute(e);
            if (!e.Cancel)
            {
                tag.RemoveAttribute(attribute.Name);
            }
        }
示例#11
0
        public async Task Have_ExpandMode_Attribute_SetToMulti_ByDefault()
        {
            // Arrange
            IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>();

            // Asset
            IAttr attr = cut.Find(FastHtmlElements.FastAccordion)
                         .Attributes
                         .GetNamedItem(FastHtmlElements.FastAccordionAttributes.ExpandMode);

            attr.Should().NotBeNull();
        }
示例#12
0
        public async Task Have_ExpandMode_Attribute_SetToSingle_WhenConfiguredSo()
        {
            // Arrange
            IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>(
                p => p.Add(pp => pp.ExpandMode, BfComponentApis.BfAccordion.ExpandModeValues.Single));

            // Asset
            IAttr attr = cut.Find(FastHtmlElements.FastAccordion)
                         .Attributes
                         .GetNamedItem(FastHtmlElements.FastAccordionAttributes.ExpandMode);

            attr.Should().NotBeNull();
        }
示例#13
0
        public async Task BeOpened_WhenConfiguredSo()
        {
            // Arrange
            IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>(
                p => p.AddChildContent <BfAccordionItem>(pp => pp.Add(
                                                             ppp => ppp.IsExpanded, true)));

            // Assert
            IAttr attr = cut.Find($"{FastHtmlElements.FastAccordion}>{FastHtmlElements.FastAccordionItem}")
                         .Attributes
                         .GetNamedItem("expanded");

            attr.Should().NotBeNull();
        }
示例#14
0
        public async Task SplatUnknownParameters()
        {
            // Arrange
            IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>(
                ("custom", "value"));

            // Assert
            IAttr attr = cut.Find(FastHtmlElements.FastAccordion)
                         .Attributes
                         .GetNamedItem("custom");

            attr.Should().NotBeNull();
            attr.Value.Should().Be("value");
        }
示例#15
0
        // disable XML comments warnings
        #pragma warning disable 1591

        public virtual string Attribute(IAttr attribute)
        {
            var namespaceUri = attribute.NamespaceUri;
            var localName    = attribute.LocalName;
            var value        = attribute.Value;
            var temp         = new StringBuilder();

            if (String.IsNullOrEmpty(namespaceUri))
            {
                temp.Append(localName);
            }
            else if (namespaceUri == NamespaceNames.XmlUri)
            {
                temp.Append(NamespaceNames.XmlPrefix).Append(':').Append(localName);
            }
            else if (namespaceUri == NamespaceNames.XLinkUri)
            {
                temp.Append(NamespaceNames.XLinkPrefix).Append(':').Append(localName);
            }
            else if (namespaceUri == NamespaceNames.XmlNsUri)
            {
                temp.Append(XmlNamespaceLocalName(localName));
            }
            else
            {
                temp.Append(attribute.Name);
            }

            temp.Append('=').Append('"');

            for (var i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                case '&': temp.Append("&amp;"); break;

                case '\u00a0': temp.Append("&nbsp;"); break;

                case '"': temp.Append("&quot;"); break;

                case '<': temp.Append("&lt;"); break;

                case '>': temp.Append("&gt;"); break;

                default: temp.Append(value[i]); break;
                }
            }

            return(temp.Append('"').ToString());
        }
示例#16
0
        public bool Equals(IAttr other)
        {
            if (object.ReferenceEquals(this, other))
            {
                return(true);
            }

            if (other == null)
            {
                return(false);
            }

            return(property == ((ElementAttributeBase <TDependencyObject, TDependencyProperty>)other).property);
        }
        /// <summary>
        /// Creates the string representation of the attribute.
        /// </summary>
        /// <param name="attr">The attribute to serialize.</param>
        /// <returns>The string representation.</returns>
        protected virtual String Attribute(IAttr attr)
        {
            var temp = StringBuilderPool.Obtain();

            WriteAttributeName(attr, temp);

            if (attr.Value != null)
            {
                temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);
                WriteAttributeValue(attr, temp);
                return(temp.Append(Symbols.DoubleQuote).ToPool());
            }

            return(temp.ToPool());
        }
示例#18
0
        String IMarkupFormatter.Attribute(IAttr attribute)
        {
            var namespaceUri = attribute.NamespaceUri;
            var localName    = attribute.LocalName;
            var value        = attribute.Value;
            var temp         = StringBuilderPool.Obtain();

            if (String.IsNullOrEmpty(namespaceUri))
            {
                temp.Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XmlUri))
            {
                temp.Append(NamespaceNames.XmlPrefix).Append(Symbols.Colon).Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XLinkUri))
            {
                temp.Append(NamespaceNames.XLinkPrefix).Append(Symbols.Colon).Append(localName);
            }
            else if (namespaceUri.Is(NamespaceNames.XmlNsUri))
            {
                temp.Append(XmlNamespaceLocalName(localName));
            }
            else
            {
                temp.Append(attribute.Name);
            }

            temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);

            for (var i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                case Symbols.Ampersand: temp.Append("&amp;"); break;

                case Symbols.NoBreakSpace: temp.Append("&#160;"); break;

                case Symbols.LessThan: temp.Append("&lt;"); break;

                case Symbols.DoubleQuote: temp.Append("&quot;"); break;

                default: temp.Append(value[i]); break;
                }
            }

            return(temp.Append(Symbols.DoubleQuote).ToPool());
        }
示例#19
0
        public async Task Splat_UnknownParameters()
        {
            // Arrange
            IRenderedComponent <BfAccordion> cut = RenderComponent <BfAccordion>(
                p => p.AddChildContent <BfAccordionItem>(
                    ppp => ppp.AddUnmatched("custom", "value")
                    ));

            // Assert
            IAttr attr = cut.Find($"{FastHtmlElements.FastAccordion}>{FastHtmlElements.FastAccordionItem}")
                         .Attributes
                         .GetNamedItem("custom");

            attr.Should().NotBeNull();
            attr.Value.Should().Be("value");
        }
示例#20
0
    public string Attribute(IAttr attr)
    {
        var namespaceUri = attr.NamespaceUri;
        var localName    = attr.LocalName;
        var value        = attr.Value;
        var sb           = new StringBuilder();

        if (string.IsNullOrEmpty(namespaceUri))
        {
            sb.Append(localName);
        }
        else if (Is(namespaceUri, NamespaceNames.XmlUri))
        {
            sb.Append(NamespaceNames.XmlPrefix).Append(':').Append(localName);
        }
        else if (Is(namespaceUri, NamespaceNames.XLinkUri))
        {
            sb.Append(NamespaceNames.XLinkPrefix).Append(':').Append(localName);
        }
        else if (Is(namespaceUri, NamespaceNames.XmlNsUri))
        {
            sb.Append(XmlNamespaceLocalName(localName));
        }
        else
        {
            sb.Append(attr.Name);
        }

        sb.Append('=').Append('"');

        for (var i = 0; i < value.Length; i++)
        {
            switch (value[i])
            {
            // Change: Don't do this as we aren't decoding incoming entities
            // case '&': temp.Append("&amp;"); break;
            case '\xA0': sb.Append("&nbsp;"); break;

            case '"': sb.Append("&quot;"); break;

            default: sb.Append(value[i]); break;
            }
        }

        return(sb.Append('"').ToString());
    }
示例#21
0
        public virtual IAttr SetAttributeNode(IAttr newAttr)
        {
            if (newAttr == null)
            {
                return(null);
            }

            if (!(newAttr is DomAttrImpl))
            {
                throw new DomException(DomException.WRONG_DOCUMENT, "newAttr not instanceof DomAttrImpl");
            }

            var    newatt = (DomAttrImpl)newAttr;
            string name   = newatt.AttValAdaptee.Attribute;
            IAttr  result = null;

            AttVal att = Adaptee.Attributes;

            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            if (att != null)
            {
                result      = att.Adapter;
                att.Adapter = newAttr;
            }
            else
            {
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = newatt.AttValAdaptee;
                }
                else
                {
                    newatt.AttValAdaptee.Next = Adaptee.Attributes;
                    Adaptee.Attributes        = newatt.AttValAdaptee;
                }
            }
            return(result);
        }
        internal static void WriteAttributeValue(IAttr attr, StringBuilder stringBuilder)
        {
            var value = attr.Value ?? String.Empty;

            for (var i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                case Symbols.Ampersand: stringBuilder.Append("&amp;"); break;

                case Symbols.NoBreakSpace: stringBuilder.Append("&nbsp;"); break;

                case Symbols.DoubleQuote: stringBuilder.Append("&quot;"); break;

                default: stringBuilder.Append(value[i]); break;
                }
            }
        }
示例#23
0
        Attr Prepare(IAttr item)
        {
            var attr = item as Attr;

            if (attr != null)
            {
                if (attr.Container == this)
                {
                    return(null);
                }
                else if (attr.Container != null)
                {
                    throw new DomException(DomError.InUse);
                }

                attr.Container = this;
            }

            return(attr);
        }
示例#24
0
        public static async Task <AttrData> Instantiate(IAttr attr)
        {
            var plainConstraints = await attr.GetConstraints();

            var dataType = await attr.GetDataType();

            var plainValues = await attr.GetValueCandidates();

            var values =
                from v in plainValues
                select new AttrValueData(v.EventValue.ID, v.EventValue.Value);

            return(new AttrData {
                ID = attr.PropertyID,
                Label = attr.Label,
                DataType = dataType,
                IsBoxed = dataType.IsBoxed,
                Values = values
            });
        }
示例#25
0
        Attr Prepare(IAttr item)
        {
            var attr = item as Attr;

            if (attr != null)
            {
                if (Object.ReferenceEquals(attr.Container, this))
                {
                    return(null);
                }
                else if (attr.Container != null)
                {
                    throw new DomException(DomError.InUse);
                }

                attr.Container = this;
            }

            return(attr);
        }
示例#26
0
        String IMarkupFormatter.Attribute(IAttr attribute)
        {
            var value = attribute.Value;
            var temp  = Pool.NewStringBuilder();

            temp.Append(attribute.Name);
            temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);

            for (int i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                case Symbols.SingleQuote: temp.Append("&apos;"); break;

                case Symbols.DoubleQuote: temp.Append("&quot;"); break;

                default: temp.Append(value[i]); break;
                }
            }

            return(temp.Append(Symbols.DoubleQuote).ToPool());
        }
示例#27
0
        public virtual IAttr RemoveAttributeNode(IAttr oldAttr)
        {
            if (oldAttr == null)
            {
                return(null);
            }

            IAttr  result;
            AttVal att = Adaptee.Attributes;
            AttVal pre = null;

            while (att != null)
            {
                if (att.Adapter == oldAttr)
                {
                    break;
                }
                pre = att;
                att = att.Next;
            }
            if (att != null)
            {
                if (pre == null)
                {
                    Adaptee.Attributes = att.Next;
                }
                else
                {
                    pre.Next = att.Next;
                }
                result = oldAttr;
            }
            else
            {
                throw new DomException(DomException.NOT_FOUND, "oldAttr not found");
            }
            return(result);
        }
        String IMarkupFormatter.Attribute(IAttr attribute)
        {
            var value = attribute.Value;
            var temp  = StringBuilderPool.Obtain();

            temp.Append(attribute.Name);
            temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);

            for (var i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                case Symbols.Ampersand: temp.Append("&amp;"); break;

                case Symbols.LessThan: temp.Append("&lt;"); break;

                case Symbols.DoubleQuote: temp.Append("&quot;"); break;

                default: temp.Append(value[i]); break;
                }
            }

            return(temp.Append(Symbols.DoubleQuote).ToPool());
        }
示例#29
0
        public IAttr SetNamedItem(IAttr item)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var name = item.Name;

                for (var i = 0; i < _items.Count; i++)
                {
                    if (name.Is(_items[i].Name))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;
                        RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        return attr;
                    }
                }

                _items.Add(proposed);
                RaiseChangedEvent(proposed, proposed.Value, null);
            }

            return null;
        }
示例#30
0
文件: Attr.cs 项目: JBTech/AngleSharp
 /// <summary>
 /// Compares the given attribute to the current one.
 /// </summary>
 /// <param name="other">The attibute to compare to.</param>
 /// <returns>
 /// True if both attributes are equal, otherwise false.
 /// </returns>
 public Boolean Equals(IAttr other)
 {
     return (String.Equals(Prefix, other.Prefix, StringComparison.Ordinal) &&
             String.Equals(NamespaceUri, other.NamespaceUri, StringComparison.Ordinal) &&
             String.Equals(Value, other.Value, StringComparison.Ordinal));
 }
示例#31
0
        Attr Prepare(IAttr item)
        {
            var attr = item as Attr;

            if (attr != null)
            {
                if (attr.Container == this)
                    return null;
                else if (attr.Container != null)
                    throw new DomException(DomError.InUse);

                attr.Container = this;
            }

            return attr;
        }
示例#32
0
        public IAttr SetNamedItemWithNamespaceUri(IAttr item)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var localName = item.LocalName;
                var namespaceUri = item.NamespaceUri;

                for (int i = 0; i < _items.Count; i++)
                {
                    if (String.Equals(_items[i].LocalName, localName, StringComparison.Ordinal) &&
                        String.Equals(_items[i].NamespaceUri, namespaceUri, StringComparison.Ordinal))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;
                        RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        return attr;
                    }
                }

                _items.Add(proposed);
                RaiseChangedEvent(proposed, proposed.Value, null);
            }

            return null;
        }
示例#33
0
        public IAttr SetNamedItemWithNamespaceUri(IAttr item, Boolean suppressMutationObservers)
        {
            var proposed = Prepare(item);

            if (proposed != null)
            {
                var localName = item.LocalName;
                var namespaceUri = item.NamespaceUri;

                for (var i = 0; i < _items.Count; i++)
                {
                    if (localName.Is(_items[i].LocalName) && namespaceUri.Is(_items[i].NamespaceUri))
                    {
                        var attr = _items[i];
                        _items[i] = proposed;

                        if (!suppressMutationObservers)
                        {
                            RaiseChangedEvent(proposed, proposed.Value, attr.Value);
                        }

                        return attr;
                    }
                }

                _items.Add(proposed);

                if (!suppressMutationObservers)
                {
                    RaiseChangedEvent(proposed, proposed.Value, null);
                }
            }

            return null;
        }
 /// <summary>
 /// Remove an attribute from the document.
 /// </summary>
 /// <param name="tag">tag where the attribute to belongs</param>
 /// <param name="attribute">to be removed</param>
 /// <param name="reason">reason why to be removed</param>
 private void RemoveAttribute(IElement tag, IAttr attribute, RemoveReason reason)
 {
     var e = new RemovingAttributeEventArgs { Tag = tag, Attribute = attribute, Reason = reason };
     OnRemovingAttribute(e);
     if (!e.Cancel) tag.RemoveAttribute(attribute.Name);
 }
示例#35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemovingAttributeEventArgs"/> class.
 /// </summary>
 /// <param name="tag">The element containing the attribute.</param>
 /// <param name="attribute">The attribute to be removed.</param>
 /// <param name="reason">The reason why the attribute will be removed.</param>
 public RemovingAttributeEventArgs(IElement tag, IAttr attribute, RemoveReason reason)
 {
     Tag       = tag;
     Attribute = attribute;
     Reason    = reason;
 }
示例#36
0
 /// <summary>
 /// Determines whether the specified attribute can contain a URI.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns><c>true</c> if the attribute can contain a URI; otherwise, <c>false</c>.</returns>
 private bool IsUriAttribute(IAttr attribute)
 {
     return(UriAttributes.Contains(attribute.Name));
 }
示例#37
0
 public IAttr SetNamedItemWithNamespaceUri(IAttr item)
 {
     return SetNamedItemWithNamespaceUri(item, false);
 }
示例#38
0
 String IMarkupFormatter.Attribute(IAttr attribute)
 {
     return HtmlMarkupFormatter.Instance.Attribute(attribute);
 }
        String IMarkupFormatter.Attribute(IAttr attribute)
        {
            var value = attribute.Value;
            var temp = Pool.NewStringBuilder();
            temp.Append(attribute.Name);
            temp.Append(Symbols.Equality).Append(Symbols.DoubleQuote);

            for (int i = 0; i < value.Length; i++)
            {
                switch (value[i])
                {
                    case Symbols.Ampersand: temp.Append("&amp;"); break;
                    case Symbols.LessThan: temp.Append("&lt;"); break;
                    case Symbols.DoubleQuote: temp.Append("&quot;"); break;
                    default: temp.Append(value[i]); break;
                }
            }

            return temp.Append(Symbols.DoubleQuote).ToPool();
        }
 /// <summary>
 /// Determines whether the specified attribute can contain a URI.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns><c>true</c> if the attribute can contain a URI; otherwise, <c>false</c>.</returns>
 private bool IsUriAttribute(IAttr attribute)
 {
     return UriAttributes.Contains(attribute.Name);
 }
示例#41
0
 /// <summary> DOM2 - not implemented. </summary>
 public virtual IAttr SetAttributeNodeNs(IAttr newAttr)
 {
     return null;
 }
 /// <summary>
 /// Formats an attribute specified by the argument.
 /// </summary>
 /// <param name="attribute">The attribute to serialize.</param>
 /// <returns>The formatted attribute.</returns>
 public String Attribute(IAttr attribute)
 {
     return ChildFormatter.Attribute(attribute);
 }
示例#43
0
        Attr Prepare(IAttr item)
        {
            var attr = item as Attr;

            if (attr != null)
            {
                if (Object.ReferenceEquals(attr.Container, this))
                {
                    return null;
                }
                else if (attr.Container != null)
                {
                    throw new DomException(DomError.InUse);
                }

                attr.Container = this;
            }

            return attr;
        }
示例#44
0
文件: Attr.cs 项目: Wojdav/AngleSharp
 public Boolean Equals(IAttr other)
 {
     return Prefix.Is(other.Prefix) && NamespaceUri.Is(other.NamespaceUri) && Value.Is(other.Value);
 }
示例#45
0
        public virtual IAttr SetAttributeNode(IAttr newAttr)
        {
            if (newAttr == null)
            {
                return null;
            }

            if (!(newAttr is DomAttrImpl))
            {
                throw new DomException(DomException.WRONG_DOCUMENT, "newAttr not instanceof DomAttrImpl");
            }

            var newatt = (DomAttrImpl) newAttr;
            string name = newatt.AttValAdaptee.Attribute;
            IAttr result = null;

            AttVal att = Adaptee.Attributes;
            while (att != null)
            {
                if (att.Attribute.Equals(name))
                {
                    break;
                }
                att = att.Next;
            }
            if (att != null)
            {
                result = att.Adapter;
                att.Adapter = newAttr;
            }
            else
            {
                if (Adaptee.Attributes == null)
                {
                    Adaptee.Attributes = newatt.AttValAdaptee;
                }
                else
                {
                    newatt.AttValAdaptee.Next = Adaptee.Attributes;
                    Adaptee.Attributes = newatt.AttValAdaptee;
                }
            }
            return result;
        }
示例#46
0
        public virtual IAttr RemoveAttributeNode(IAttr oldAttr)
        {
            if (oldAttr == null)
            {
                return null;
            }

            IAttr result;
            AttVal att = Adaptee.Attributes;
            AttVal pre = null;
            while (att != null)
            {
                if (att.Adapter == oldAttr)
                {
                    break;
                }
                pre = att;
                att = att.Next;
            }
            if (att != null)
            {
                if (pre == null)
                {
                    Adaptee.Attributes = att.Next;
                }
                else
                {
                    pre.Next = att.Next;
                }
                result = oldAttr;
            }
            else
            {
                throw new DomException(DomException.NOT_FOUND, "oldAttr not found");
            }
            return result;
        }
示例#47
0
 /// <summary>
 /// Determines whether the specified attribute is allowed.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns>
 private bool IsAllowedAttribute(IAttr attribute)
 {
     return(AllowedAttributes.Contains(attribute.Name)
            // test html5 data- attributes
            || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase)));
 }
 /// <summary>
 /// Determines whether the specified attribute is allowed.
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <returns><c>true</c> if the attribute is allowed; otherwise, <c>false</c>.</returns>
 private bool IsAllowedAttribute(IAttr attribute)
 {
     return AllowedAttributes.Contains(attribute.Name)
         // test html5 data- attributes
         || (AllowDataAttributes && attribute.Name != null && attribute.Name.StartsWith("data-", StringComparison.OrdinalIgnoreCase));
 }