Exemplo n.º 1
0
        /// <summary>
        ///     Converts a TLVData into an XmlNode representation, enhanced with the long name of the field found in the
        ///     <paramref name="dictionary" />
        /// </summary>
        /// <param name="tlv">Source data to convert</param>
        /// <param name="xmlDoc">XML document used to create elements</param>
        /// <param name="dictionary">TLV Dictionary to use to find the long name</param>
        /// <returns>A new XmlNode</returns>
        public static XElement ToXmlNode(this TlvData tlv, XDocument xmlDoc, TlvDictionary dictionary)
        {
            var xmlNode = tlv.ToXmlNode(xmlDoc);

            InsertDictionaryInformation(xmlNode, dictionary);
            InsertDictionaryInformation(xmlNode.Descendants("tlvData"), dictionary);

            return(xmlNode);
        }
Exemplo n.º 2
0
        private static void InsertDictionaryInformation(XElement xmlNode, TlvDictionary dictionary)
        {
            var description = dictionary.Get(xmlNode.Attribute("tag").Value);

            if (description != null)
            {
                xmlNode.Ancestors().Last().SetAttributeValue("longName", description.LongName);
            }
        }
Exemplo n.º 3
0
 private static void InsertDictionaryInformation(IEnumerable <XElement> xmlNodeList, TlvDictionary dictionary)
 {
     foreach (var xmlNode in xmlNodeList)
     {
         InsertDictionaryInformation(xmlNode, dictionary);
         InsertDictionaryInformation(xmlNode.Descendants("tlvData"), dictionary);
     }
 }
Exemplo n.º 4
0
 /// <summary>
 ///     Export a TLV object to XML format using a dictionnary to resolve formating
 /// </summary>
 /// <param name="tlv">Source object</param>
 /// <param name="dictionary">TLV Dictionary to use to find the long name</param>
 /// <returns>The <c>string</c> representation</returns>
 public static string ToXmlString(this TlvData tlv, TlvDictionary dictionary)
 {
     return(tlv.ToXmlNode(new XDocument(), dictionary).Value);
 }