73 lines
2.2 KiB
C#
73 lines
2.2 KiB
C#
using System.Collections.Generic;
|
|
using System.Collections.Specialized;
|
|
using System.Security;
|
|
using Bloomberg.Message.Components;
|
|
|
|
namespace Bloomberg.Message.Writer
|
|
{
|
|
public class XmlWriter : VariableLengthWriter
|
|
{
|
|
public const string XmlElement = "elem";
|
|
public const string XmlElementName = "n";
|
|
public const string XmlElementValue = "v";
|
|
public const string XmlElementType = "type";
|
|
public const string XmlAttribute = "attr";
|
|
|
|
public XmlWriter(DataSender sender)
|
|
: base(sender)
|
|
{
|
|
}
|
|
|
|
public void WriteXmlHeader()
|
|
{
|
|
Write("<?xml version=\"1.0\" encoding=\"" + Utils.MessageConstants.MessageEncoding.HeaderName + "\"?>\n");
|
|
}
|
|
|
|
public void WriteElement(string elementName, NameValueCollection attributes)
|
|
{
|
|
WriteElement(elementName, attributes, true);
|
|
}
|
|
|
|
public void WriteElement(string elementName, NameValueCollection attributes, bool closeElement)
|
|
{
|
|
string xml = "<" + elementName;
|
|
|
|
foreach (string name in attributes)
|
|
{
|
|
xml += " " + name + "=\"" + SecurityElement.Escape(attributes[name]) + "\"";
|
|
}
|
|
|
|
if (closeElement)
|
|
xml += "/>\n";
|
|
else
|
|
xml += ">\n";
|
|
attributes.Clear();
|
|
Write(xml);
|
|
}
|
|
|
|
public void WriteNameValueAttribute(List<KeyValuePair<string, string>> attributes)
|
|
{
|
|
string xml = "";
|
|
foreach (KeyValuePair<string, string> keyPair in attributes)
|
|
{
|
|
xml += "<" + XmlAttribute +
|
|
" " + XmlElementName + "=\"" + SecurityElement.Escape(keyPair.Key) + "\"" +
|
|
" " + XmlElementValue + "=\"" + SecurityElement.Escape(keyPair.Value) + "\"" +
|
|
"/>";
|
|
}
|
|
attributes.Clear();
|
|
Write(xml);
|
|
}
|
|
|
|
public void WriteStartElement(string elementName)
|
|
{
|
|
Write("<" + elementName + ">");
|
|
}
|
|
|
|
public void WriteCloseElement(string elementName)
|
|
{
|
|
Write("</" + elementName + ">");
|
|
}
|
|
|
|
}
|
|
}
|