/// <summary>Create a XML start element.</summary> /// <remarks>Create a XML start element.</remarks> /// <param name="name">- the tag name.</param> /// <param name="nameSpace">- namespace of the tag name</param> /// <param name="attributes">- an ordered collection of attributes (names and values) to render with the element</param> /// <param name="indentLevel">- the indent level</param> /// <param name="close">- indicates whether or not close the element.</param> /// <param name="lineBreak">- indicates whether or not to include a line break</param> /// <returns>- the formatted result.</returns> public static string CreateStartElement(string name, string nameSpace, IList <KeyValuePair <string, string> > attributes, int indentLevel, bool close, bool lineBreak) { StringBuilder buffer = new StringBuilder(); Indenter.IndentBuffer(buffer, indentLevel); buffer.Append("<"); buffer.Append(name); if (nameSpace != null) { buffer.Append(" xmlns=\"" + nameSpace + "\""); } if (attributes != null) { foreach (KeyValuePair <string, string> attribute in attributes) { buffer.Append(SPACE); buffer.Append(attribute.Key); buffer.Append(EQUALS); buffer.Append(QUOTE); buffer.Append(XmlStringEscape.Escape(attribute.Value)); buffer.Append(QUOTE); } } if (close) { buffer.Append("/"); } buffer.Append(">"); if (lineBreak) { buffer.Append(SystemUtils.LINE_SEPARATOR); } return(buffer.ToString()); }
/// <summary>Create a closing element tag.</summary> /// <remarks>Create a closing element tag.</remarks> /// <param name="name">- the tag name</param> /// <param name="indentLevel">- the indent level</param> /// <param name="lineBreak">- a flag to indicate if a line break should terminate the tag</param> /// <returns>- the formatted result</returns> public static string CreateEndElement(string name, int indentLevel, bool lineBreak) { StringBuilder buffer = new StringBuilder(); Indenter.IndentBuffer(buffer, indentLevel); buffer.Append("</"); buffer.Append(name); buffer.Append(">"); if (lineBreak) { buffer.Append(SystemUtils.LINE_SEPARATOR); } return(buffer.ToString()); }
private void AppendNamePart(StringBuilder buffer, EntityNamePart namePart, int indentLevel) { string openTag = string.Empty; string closeTag = string.Empty; bool valueProvided = namePart.Value != null; if (namePart.Type != null) { openTag = "<" + namePart.Type.Value + AddQualifier(namePart) + AddNullFlavor(namePart) + (valueProvided ? string.Empty : "/") + ">"; closeTag = "</" + namePart.Type.Value + ">"; } Indenter.IndentBuffer(buffer, indentLevel); buffer.Append(openTag); if (valueProvided) { buffer.Append(XmlStringEscape.Escape(namePart.Value)); buffer.Append(closeTag); } buffer.Append(SystemUtils.LINE_SEPARATOR); }
private void AppendPostalAddressPart(StringBuilder buffer, PostalAddressPart postalAddressPart, int indentLevel) { bool hasPartType = postalAddressPart.Type != null; bool hasValue = postalAddressPart.Value != null && postalAddressPart.Value.Length > 0; string tagName = (hasPartType ? postalAddressPart.Type.Value : string.Empty); if (hasPartType) { if (!hasValue) { buffer.Append(CreateElement(tagName, null, indentLevel, true, true)); } else { buffer.Append(CreateElement(tagName, GetCodeAttributes(postalAddressPart.Code), indentLevel, false, false)); } } if (hasValue) { if (!hasPartType) { Indenter.IndentBuffer(buffer, indentLevel); } string xmlEscapedValue = XmlStringEscape.Escape(postalAddressPart.Value); if (xmlEscapedValue != null) { buffer.Append(xmlEscapedValue); } } if (hasPartType && hasValue) { buffer.Append(CreateElementClosure(tagName, 0, true)); } else { buffer.Append(SystemUtils.LINE_SEPARATOR); } }
public virtual void RenderContent(EncapsulatedData encapsulatedData, StringBuilder buffer, int indentLevel, FormatContext context, bool hasReferenceOrThumbnailOrDocument) { bool hasContent = (encapsulatedData.Content != null); if (hasReferenceOrThumbnailOrDocument && hasContent) { Indenter.IndentBuffer(buffer, indentLevel); } if (hasContent) { string textContent = encapsulatedData.Content; if (EdRepresentation.B64.Equals(encapsulatedData.Representation)) { ValidateBase64Encoded("content", textContent, context); } buffer.Append(textContent); } if (hasReferenceOrThumbnailOrDocument && hasContent) { buffer.Append(SystemUtils.LINE_SEPARATOR); } }