/// <summary> /// Adds the attribute with the adjusted prefix, namespace and name. /// </summary> /// <param name="element"></param> /// <param name="name"></param> /// <param name="value"></param> public static void SetAdjustedAttribute(Element element, String name, String value) { switch (name) { case "xlink:actuate": case "xlink:arcrole": case "xlink:href": case "xlink:role": case "xlink:show": case "xlink:title": case "xlink:type": element.SetAttributeNode(new Attr(GetName(name), value) { Prefix = "xlink", NamespaceURI = Namespaces.XLink }); break; case "xml:base": case "xml:lang": case "xml:space": element.SetAttributeNode(new Attr(GetName(name), value) { Prefix = "xml", NamespaceURI = Namespaces.Xml }); break; case "xmlns": element.SetAttributeNS(Namespaces.XmlNS, name, value); break; case "xmlns:xlink": element.SetAttributeNode(new Attr(GetName(name), value) { Prefix = "xmlns", NamespaceURI = Namespaces.XmlNS }); break; default: element.SetAttribute(name, value); break; } }
public override Boolean Apply(Element element) { if (!element.HasAttribute(Parent.Name)) element.SetAttribute(Parent.Name, Value); else if (IsFixed) return element.GetAttribute(Parent.Name) == Value; return true; }
/// <summary> /// Copies the attributes from the source element to the target element. /// Each attribute will be recreated on the target. /// </summary> /// <param name="source">The source of the attributes.</param> /// <param name="target">The target where to create the attributes.</param> protected static void CopyAttributes(Element source, Element target) { target._namespace = source._namespace; target._prefix = source._prefix; for (int i = 0; i < source._attributes.Count; i++) target.SetAttribute(source._attributes[i].Name, source._attributes[i].Value); }
/// <summary> /// Checks for each attribute on the token if the attribute is already present on the node. /// If it is not, the attribute and its corresponding value is added to the node. /// </summary> /// <param name="elementToken">The token with the source attributes.</param> /// <param name="element">The node with the target attributes.</param> void AppendAttributes(HtmlTagToken elementToken, Element element) { foreach (var attr in elementToken.Attributes) { if (!element.HasAttribute(attr.Key)) element.SetAttribute(attr.Key, attr.Value); } }
/// <summary> /// Modifies the node by appending all attributes and /// acknowledging the self-closing flag if set. /// </summary> /// <param name="element">The node which will be added to the list.</param> /// <param name="elementToken">The associated tag token.</param> /// <param name="acknowledgeSelfClosing">Should the self-closing be acknowledged?</param> void SetupElement(Element element, HtmlToken elementToken, bool acknowledgeSelfClosing) { var tag = (HtmlTagToken)elementToken; element.NodeName = tag.Name; if (tag.IsSelfClosing && !acknowledgeSelfClosing) RaiseErrorOccurred(ErrorCode.TagCannotBeSelfClosed); for (var i = 0; i < tag.Attributes.Count; i++) element.SetAttribute(tag.Attributes[i].Key, tag.Attributes[i].Value); }
/// <summary> /// Appends the attributes of the given tag token to the given node. /// </summary> /// <param name="elementToken">The tag token which carries the modifications.</param> /// <param name="element">The node which should be modified.</param> void AddAttributesToElement(HtmlTagToken elementToken, Element element) { for (var i = 0; i < elementToken.Attributes.Count; i++) element.SetAttribute(elementToken.Attributes[i].Key, elementToken.Attributes[i].Value); }