/// <summary>Copy a whole set of attributes.</summary> public virtual void SetAttributes(IAttributes atts) { if (atts == null) { throw new ArgumentNullException("atts"); } Clear(); int attLen = atts.Length; if (Capacity < attLen) { Capacity = attLen; } for (int attIndx = 0; attIndx < attLen; attIndx++) { InternalSetAttribute( ref this.atts[attIndx], atts.GetUri(attIndx), atts.GetLocalName(attIndx), atts.GetQName(attIndx), atts.GetType(attIndx), atts.GetValue(attIndx), atts.IsSpecified(attIndx)); } }
//////////////////////////////////////////////////////////////////// // Manipulators //////////////////////////////////////////////////////////////////// /// <summary> /// Copy an entire Attributes object. The "specified" flags are /// assigned as true, and "declared" flags as false (except when /// an attribute's type is not CDATA), /// unless the object is an Attributes2 object. /// In that case those flag values are all copied. /// </summary> /// <seealso cref="Attributes.SetAttributes(IAttributes)"/> public override void SetAttributes(IAttributes atts) { int length = atts.Length; base.SetAttributes(atts); declared = new bool[length]; specified = new bool[length]; if (atts is Attributes2) { Attributes2 a2 = (Attributes2)atts; for (int i = 0; i < length; i++) { declared[i] = a2.IsDeclared(i); specified[i] = a2.IsSpecified(i); } } else { for (int i = 0; i < length; i++) { declared[i] = !"CDATA".Equals(atts.GetType(i)); specified[i] = true; } } }
private void SetAttributesInternal(IAttributes atts) { int length = atts.Length; base.SetAttributes(atts); _declared = new bool[length]; _specified = new bool[length]; var a2 = atts as IAttributes2; if (a2 != null) { for (int i = 0; i < length; i++) { _declared[i] = a2.IsDeclared(i); _specified[i] = a2.IsSpecified(i); } } else { for (int i = 0; i < length; i++) { _declared[i] = !"CDATA".Equals(atts.GetType(i)); _specified[i] = true; } } }
/// <summary>Add an attribute taken from an existing set of attributes.</summary> /// <returns>Index of added attribute.</returns> public virtual int AddAttribute(IAttributes atts, int index) { if (atts == null) { throw new ArgumentNullException("atts"); } return(AddAttribute( atts.GetUri(index), atts.GetLocalName(index), atts.GetQName(index), atts.GetType(index), atts.GetValue(index), atts.IsSpecified(index))); }
public void SetAttributes(IAttributes attributes) { this.Clear(); length = attributes.GetLength(); if (length > 0) { data = new string[length * 5]; for (int i = 0; i < length; i++) { data[i * 5] = attributes.GetURI(i); data[i * 5 + 1] = attributes.GetLocalName(i); data[i * 5 + 2] = attributes.GetQName(i); data[i * 5 + 3] = attributes.GetType(i); data[i * 5 + 4] = attributes.GetValue(i); } } }
private void SetAttributesInternal(IAttributes atts) { ClearInternal(); int length = atts.Length; if (length > 0) { _data = new string[length * 5]; for (int i = 0; i < length; i++) { _data[i * 5] = atts.GetUri(i); _data[i * 5 + 1] = atts.GetLocalName(i); _data[i * 5 + 2] = atts.GetQName(i); _data[i * 5 + 3] = atts.GetType(i); _data[i * 5 + 4] = atts.GetValue(i); } _length = length; } }
public void StartElement(string uri, string localName, string qName, IAttributes atts) { seenEvent = true; if (inProlog) { FlushProlog(); inProlog = false; } FlushEndPrefixMappings(); if (startPrefixMappings != null) { for (int i = 0; i < startPrefixMappings.Count; i++) { string[] mapping = (string[])startPrefixMappings.GetByIndex(i); writer.WriteStartElement("startPrefixMapping"); writer.WriteStartElement("prefix"); writer.WriteString(mapping[0]); writer.WriteEndElement(); writer.WriteStartElement("data"); writer.WriteString(mapping[1]); writer.WriteEndElement(); writer.WriteEndElement(); } startPrefixMappings = null; } writer.WriteStartElement("startElement"); if (uri != null) { writer.WriteStartElement("namespaceURI"); writer.WriteString(uri); writer.WriteEndElement(); } if (localName != null) { writer.WriteStartElement("localName"); writer.WriteString(localName); writer.WriteEndElement(); } if (qName != null) { writer.WriteStartElement("qualifiedName"); writer.WriteString(qName); writer.WriteEndElement(); } writer.WriteStartElement("attributes"); SortedList sortedAtts = new SortedList(); for (int i = 0; i < atts.Length; i++) { string ln = atts.GetLocalName(i); string qn = atts.GetQName(i); string ns = atts.GetUri(i); string key = ""; if (ln != null) key += ln; key += '\u0000'; if (qn != null) key += qn; key += '\u0000'; if (ns != null) key += ns; sortedAtts.Add(key, i); } for (int i = 0; i < sortedAtts.Count; i++) { int index = (int)sortedAtts.GetByIndex(i); string ln = atts.GetLocalName(i); string qn = atts.GetQName(i); string ns = atts.GetUri(i); string val = atts.GetValue(i); string typ = atts.GetType(i); writer.WriteStartElement("attribute"); if (ns != null) { writer.WriteStartElement("namespaceURI"); writer.WriteString(ns); writer.WriteEndElement(); } if (ln != null) { writer.WriteStartElement("localName"); writer.WriteString(ln); writer.WriteEndElement(); } if (qn != null) { writer.WriteStartElement("qualifiedName"); writer.WriteString(qn); writer.WriteEndElement(); } writer.WriteStartElement("value"); writer.WriteString(Escape(val)); writer.WriteEndElement(); writer.WriteStartElement("type"); writer.WriteString(Escape(typ)); writer.WriteEndElement(); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndElement(); }