private void WriteValueInfo(XmlWriteAdaptor adaptor, string className, ValueFormat valueFormat) { adaptor.WriteAttribute(Constants.Xml.ClassAttribute, className); string format; switch (valueFormat) { case ValueFormat.LinkMeXml: format = Constants.Xml.LinkMeFormat; break; case ValueFormat.SystemXml: format = Constants.Xml.SystemFormat; break; case ValueFormat.String: format = Constants.Xml.StringFormat; break; default: format = string.Empty; break; } adaptor.WriteAttribute(Constants.Xml.FormatAttribute, format); }
public void WriteXsiTypeAttribute(XmlWriteAdaptor adaptor) { const string method = "WriteXsiTypeAttribute"; if (adaptor == null) { throw new NullParameterException(GetType(), method, "adaptor"); } if (m_xmlTypeQualifiedName.Namespace == Constants.Xml.Namespace) { // Get the LinkMe Type prefix or write it if not found. string prefix = adaptor.WriteNamespace(Constants.Xml.Prefix, Constants.Xml.Namespace); adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, prefix + ":" + m_xmlTypeQualifiedName.Name); } else { // XSD type - no prefix. adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, m_xmlTypeQualifiedName.Name); } }
internal void WriteXml(XmlWriteAdaptor adaptor, string elementName) { if (m_headers.Count == 0) { return; // Don't write an empty element. } adaptor.WriteStartElement(elementName); for (int index = 0; index < m_headers.Count; ++index) { adaptor.WriteStartElement(Constants.Xml.HttpDetail.Headers.HeaderElement); adaptor.WriteAttribute(Constants.Xml.HttpDetail.Headers.NameAttribute, m_headers.GetKey(index)); string[] values = m_headers.GetValues(index); if (values == null) { adaptor.WriteXsiNilAttribute(true); } else { foreach (string value in values) { adaptor.WriteElement(Constants.Xml.HttpDetail.Headers.ValueElement, value); } } adaptor.WriteEndElement(); } adaptor.WriteEndElement(); }
protected override void WriteContents(XmlWriteAdaptor adaptor) { adaptor.WriteStartElement(Constants.Xml.Exception.PropertiesElement); // Write out all properties. foreach (PropertyInfo propertyInfo in PropertyInfos) { // Write an element for each property, indicating whether it is null or not. adaptor.WriteStartElement(propertyInfo.Name); object value = m_properties[propertyInfo.Name]; if (value == null) { adaptor.WriteAttribute(Constants.Xsi.Prefix, Constants.Xsi.NilAttribute, Constants.Xsi.Namespace, XmlConvert.ToString(true)); } else { adaptor.WriteElementValue(TypeXmlConvert.ToString(m_properties[propertyInfo.Name], propertyInfo.Type)); } adaptor.WriteEndElement(); } adaptor.WriteEndElement(); }
private static void WriteDictionaryToXml(XmlWriteAdaptor writer, IDictionary dictionary, string elementName) { if (dictionary.Count > 0) { writer.WriteStartElement(elementName); IDictionaryEnumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { string childElementName = XmlConvert.EncodeName((string)enumerator.Key); if (enumerator.Value == null) { writer.WriteStartElement(childElementName); writer.WriteAttribute("null", "true"); writer.WriteEndElement(); } else if (enumerator.Value is IDictionary) { WriteDictionaryToXml(writer, (IDictionary)enumerator.Value, childElementName); } else { Debug.Assert(enumerator.Value is string, "enumerator.Value is string"); writer.WriteElement(childElementName, (string)enumerator.Value); } } writer.WriteEndElement(); } }
public void WriteXml(XmlWriter xmlWriter) { XmlWriteAdaptor adaptor = new XmlWriteAdaptor(xmlWriter, GetXmlNamespace()); adaptor.WriteNamespace("lm", GetXmlNamespace()); WriteNamespaces(adaptor); adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, GetType().Name); WriteXml(adaptor); }
public void WriteOuterXml(XmlWriter xmlWriter) { XmlWriteAdaptor adaptor = new XmlWriteAdaptor(xmlWriter, GetXmlNamespace()); adaptor.WriteStartElement(Constants.Xml.Exception.ExceptionElement); adaptor.WriteNamespace(GetXmlNamespace()); WriteNamespaces(adaptor); adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, GetType().Name); WriteXml(adaptor); adaptor.WriteEndElement(); }
private static void WriteInnerException(XmlWriteAdaptor adaptor, System.Exception innerException) { adaptor.WriteStartElement(Constants.Xml.Exception.InnerExceptionElement); // InnerException. if (innerException == null) { adaptor.WriteAttribute(Constants.Xsi.NilAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, true); } else { // Determine whether the exception is serializable itself. if (innerException is IXmlSerializable) { adaptor.WriteAttribute(Constants.Xml.Exception.ClassAttribute, innerException.GetType().AssemblyQualifiedName); ((IXmlSerializable)innerException).WriteOuterXml(adaptor.XmlWriter); } else { // The class to write out depends on whether or not this is a SystemException. if (innerException is SystemException) { adaptor.WriteAttribute(Constants.Xml.Exception.ClassAttribute, ((SystemException)innerException).Class); } else { adaptor.WriteAttribute(Constants.Xml.Exception.ClassAttribute, innerException.GetType().AssemblyQualifiedName); } adaptor.WriteAttribute(Constants.Xml.Exception.IsSystemAttribute, true); WriteSystemException(adaptor, innerException); } } adaptor.WriteEndElement(); }
private void WriteXml(XmlWriteAdaptor adaptor) { foreach (IEventDetail eventDetail in _details) { var serializable = eventDetail as IXmlSerializable; if (serializable != null) { adaptor.WriteStartElement(Constants.Xml.EventDetails.EventDetailElement); adaptor.WriteAttribute(Constants.Xml.ClassAttribute, eventDetail.GetType().AssemblyQualifiedName); serializable.WriteOuterXml(adaptor.XmlWriter); adaptor.WriteEndElement(); } else { Debug.Fail("Event detail type '" + eventDetail.GetType().FullName + "' is not IXmlSerializable."); } } }
public void WriteXsiTypeAttribute(XmlWriteAdaptor adaptor) { const string method = "WriteXsiTypeAttribute"; if (adaptor == null) { throw new NullParameterException(GetType(), method, "adaptor"); } string typeName; if (_namespace.Length > 0) { // Find the existing prefix for this namespace or write a new namespace declaration. string prefix = adaptor.LookupPrefix(_namespace); if (prefix == null) { prefix = GetNameFromFullNameUnchecked(_namespace).ToLower(); adaptor.WriteNamespace(prefix, _namespace); } typeName = prefix + ":" + _name; } else { typeName = _name; } // Append the version with a "-", which is valid in a QName. if (_version != null) { typeName += "-" + _version; } // Write xsi:type. adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, typeName); }
private static void WriteSystemException(XmlWriteAdaptor adaptor, System.Exception exception) { // Write out the root element, adding appropriate namespace and type attributes. adaptor.WriteStartElement(Constants.Xml.Exception.ExceptionElement); adaptor.WriteAttribute(Constants.Xsi.TypeAttribute, Constants.Xsi.Prefix, Constants.Xsi.Namespace, "Exception"); /* * if ( exception is SystemException ) * adaptor.WriteAttribute(Constants.Xml.ClassAttribute, ((SystemException) exception).Class); * else * adaptor.WriteAttribute(Constants.Xml.ClassAttribute, exception.GetType().AssemblyQualifiedName); */ // Standard properties. adaptor.WriteElement(Constants.Xml.Exception.MessageElement, exception.Message); adaptor.WriteElement(Constants.Xml.Exception.SourceElement, exception.Source); WriteInnerException(adaptor, exception.InnerException); adaptor.WriteElement(Constants.Xml.Exception.StackTraceElement, exception.StackTrace); adaptor.WriteEndElement(); }