internal override Node Clone(Node parent) { Attr attr = new Attr(); attr.ownerDocument = parent.ownerDocument; attr.Begin = this.Begin; attr.End = this.End; attr.NameBegin = this.NameBegin; attr.NameLength = this.NameLength; attr.ValueBegin = this.ValueBegin; attr.ValueLength = this.ValueLength; return(attr); }
internal override Node Clone(Node parent) { Element clone = new Element(this.Name); clone.parentNode = parent; clone.ChildIndex = this.ChildIndex; parent.ChildNodeList.Add(clone); ((Node)clone).Index = base.Index; parent.ownerDocument.AllNodes.Add(clone); clone.ownerDocument = parent.ownerDocument; clone.Begin = this.Begin; clone.End = this.End; clone.InnerBegin = this.InnerBegin; clone.InnerEnd = this.InnerEnd; clone.AllNodesCount = this.AllNodesCount; clone.AllElementsCount = this.AllElementsCount; foreach (Attr i in this.attributes) { Attr attr = (Attr)i.Clone(clone); attr.Element = clone; clone.attributes.AddItem(attr); } clone.Index = this.Index; parent.ownerDocument.all.Add(clone); clone.ChildNodeList.Capacity = this.ChildNodeList.Capacity; foreach (Node i in this.ChildNodeList) { Node child = i.Clone(clone); } return(clone); }
internal override void OnChangeNamedItem(Node reference, Node replace) { Element element = (Element)reference; Attr attr = (Attr)replace; int stringIndex = attr.Begin; bool inOpenTag = attr.InOpenTag; attr.OnRemoveNamedItem(); element.attributes.Insert(attr.ChildIndex, this); string postfix = Symbol.Space; if (element.ownerDocument.End > stringIndex) { if (element.ownerDocument.Content[stringIndex + 1] == Symbol.Space[0]) { postfix = ""; } } else { postfix = ""; } element.ownerDocument.Content = element.ownerDocument.Content.Insert(stringIndex, this.Content + postfix); int length = this.End - this.Begin + 1 + postfix.Length; int next = this.ChildIndex + 1; if (element.attributes.Count > next) { element.attributes[next].Shift(length); } element.OnAttributesChange(length, inOpenTag); this.Element = element; this.ownerDocument = element.ownerDocument; this.SetIndex(stringIndex); this.ownerDocument.SelfCheck(); }
internal void AddIndex(Attr attr) { switch (attr.name) { case "id": this.IndexOnId.Add(attr.value, attr.Element); break; case "class": this.AddIndexOnClass(attr.value, attr.Element); break; case "name": this.IndexOnName.Add(attr.value, attr.Element); break; } }
internal void RemoveIndex(Attr attr) { switch (attr.name) { case "id": this.IndexOnId.Remove(attr.value); break; case "class": this.RemoveIndexOnClass(attr.value, attr.Element); break; case "name": this.IndexOnName.Remove(attr.value, attr.Element); break; } }
private IEnumerable <Element> GetElementsByAttr(IEnumerable <Element> source) { return(source.SelectMany(i => i.EnumerateAllElements().Where(j => { if (this.Value.IsNull()) { return j.attributes[this.Name].IsNotNull(); } else { Attr attr = j.attributes[this.Name]; if (attr.IsNull()) { return false; } else { return attr.value == this.Value; } } }))); }
/// <summary> /// 移除指定的属性节点 /// </summary> /// <param name="attr"></param> /// <returns></returns> public Attr removeAttributeNode(Attr attr) { return(this.attributes.removeNamedItem(attr.name)); }
/// <summary> /// 设置或更改指定属性节点 /// </summary> /// <param name="attr"></param> /// <returns></returns> public Attr setAttributeNode(Attr attr) { return(this.attributes.setNamedItem(attr)); }
/// <summary> /// 返回元素节点的指定属性值 /// </summary> /// <param name="name"></param> /// <returns></returns> public string getAttribute(string name) { Attr attr = this.getAttributeNode(name); return(attr.IsNotNull() ? attr.value : null); }