Ejemplo n.º 1
0
        /// <summary>
        ///     Returns the XML representation of the passed strings and the passed resource type (bool, string, dimension etc)
        /// </summary>
        /// <param name="resourceType"></param>
        /// <param name="strings"></param>
        /// <returns></returns>
        public static string GetXmlContent(ResourceType resourceType, IDictionary <string, string> strings)
        {
            var units = string.Empty;

            if (resourceType == ResourceType.Dimension)
            {
                units = "dp";
            }

            if (resourceType == ResourceType.Font)
            {
                units = "sp";
            }

            var builder = new StringBuilder();

            builder.Append(Config.AndroidXmlHeader);
            builder.AppendLine("<resources>");

            foreach (var key in strings.Keys)
            {
                var escapedString = strings[key].EscapeString();

                if (Regex.IsMatch(escapedString, "<.+>"))
                {
                    escapedString = "<![CDATA[" + escapedString + "]]>";
                }
                else
                {
                    escapedString = escapedString.EscapeForXml();
                }

                builder.Append("    ");
                builder.AppendLine(
                    string.Format(
                        "<{0} name=\"{1}\">{2}{3}</{0}>",
                        resourceType.AndroidXmlType(),
                        key,
                        escapedString,
                        units
                        )
                    );
            }

            builder.AppendLine("</resources>");

            return(builder.ToString());
        }