private void EndTag(DomElementState element) { WriteIndent(); Append("</"); Append(element.Name); Append(">"); _needIndent = true; }
public override void WriteStartElement(DomName name) { _state.StartElement(); ImpliesElementWithChildNodes(); var element = new DomElementState(name.LocalName); _elements.Push(element); }
private void DoWriteAttributes(DomElementState element) { if (element.Attributes.Count == 0) { return; } if (WriterSettings.AlignAttributes == DomAttributeAlignment.Unaligned) { DoSimpleWriteAttributes(element); return; } // Align attributes and pad either left or right var attributes = element.Attributes; int padding = attributes.Max(a => a.Name.Length); var pad = PadFunc(); int index = 0; foreach (var attribute in attributes) { bool last = index == attributes.Count - 1; bool first = index == 0; string name = attribute.Name; if (first) { name = pad(name, padding); } else { name = IndentString + pad( name, padding + element.Name.Length + 2 ); } Append(name); Append(_spaceAroundAttributeEqual); Append("="); Append(_spaceAroundAttributeEqual); Append(_quoteChar); Append(EscapeText(attribute.Value)); Append(_quoteChar); if (!last) { AppendLine(); } index++; } }
private void DoSimpleWriteAttributes(DomElementState element) { bool space = false; foreach (var attribute in element.Attributes) { if (space) { Append(" "); } space = true; Append(attribute.Name); Append(_spaceAroundAttributeEqual); Append("="); Append(_spaceAroundAttributeEqual); Append(_quoteChar); Append(EscapeText(attribute.Value)); Append(_quoteChar); } }
private void StartTag(DomElementState element, bool close) { WriteIndent(); Append("<"); Append(element.Name); if (element.Attributes.Any()) { Append(" "); } DoWriteAttributes(element); // Add a space unless attributes are using alignment bool addlSpace = WriterSettings.Indent && WriterSettings.AlignAttributes != DomAttributeAlignment.Unaligned; if (addlSpace && close) { Append(" "); } Append(close ? "/>" : ">"); _needIndent = true; }