Exemplo n.º 1
0
        protected static XmlNode SerializeToXmlElement(string serializedValue)
        {
            XmlDocument doc      = new XmlDocument();
            XmlElement  valueXml = doc.CreateElement("value");

            if (serializedValue == null)
            {
                serializedValue = string.Empty;
            }

            // We need to escape string serialized values
            serializedValue   = XmlEscaper.Escape(serializedValue);
            valueXml.InnerXml = serializedValue;

            // Hack to remove the XmlDeclaration that the XmlSerializer adds.
            XmlNode unwanted = null;

            foreach (XmlNode child in valueXml.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.XmlDeclaration)
                {
                    unwanted = child;
                    break;
                }
            }

            if (unwanted != null)
            {
                valueXml.RemoveChild(unwanted);
            }

            return(valueXml);
        }
Exemplo n.º 2
0
 private static IStringProperty SettingToProperty(SettingElement setting)
 {
     if (setting == null)
     {
         return(null);
     }
     return(new StringProperty(setting.Name, XmlEscaper.Unescape(setting.Value.ValueXml.InnerXml)));
 }
Exemplo n.º 3
0
 protected static string GetParamStr(string key, string value)
 {
     if (value == null)
     {
         return(key + '=');
     }
     return(key + '=' + StringQuoter + XmlEscaper.Escape(value) + StringQuoter);
 }
Exemplo n.º 4
0
 public static XDocument ReadAllXml(Stream stream, LoadOptions options, bool uxMode)
 {
     using (var reader = new StreamReader(stream))
     {
         var code = reader.ReadToEnd();
         code = CDataPreProcessor.InsertCData(code, "JavaScript");
         code = new XmlEscaper(code).Process();
         using (var memoryStream = new MemoryStream(Encoding.UTF8.GetBytes(code)))
             return(uxMode ? LoadUX(memoryStream, options) : XElement.Load(memoryStream).Document);
     }
 }
Exemplo n.º 5
0
        private void onAttribute(Attribute_ attribute)
        {
            sb.Append(" ");
            string nspace = this.namespaces.getPrefixViaUri(attribute.getNamespace());

            if (nspace == null)
            {
                nspace = attribute.getNamespace();
            }
            if (nspace != null && !nspace.Equals(string.Empty))
            {
                sb.Append(nspace).Append(':');
            }
            string escapedFinalValue = XmlEscaper.escapeXml10(attribute.getValue());

            sb.Append(attribute.getName()).Append('=').Append('"').Append(escapedFinalValue).Append('"');
        }
Exemplo n.º 6
0
        protected static KeyValuePair <string, string> ParseParameter(string content, ref int currentIndex)
        {
            var endIndex = content.IndexOf('=', currentIndex);

            if (endIndex < 0)
            {
                throw new InvalidOperationException("Unrecognized format of TCP message content (badly formatted parameter for item): " + content);
            }

            var key = content.Substring(currentIndex, endIndex - currentIndex);

            currentIndex = endIndex + 1;

            var quoted = false;

            if (content[currentIndex] == StringQuoter)
            {
                endIndex = content.IndexOf(StringQuoter, ++currentIndex);
                quoted   = true;
            }
            else
            {
                var andIndex       = content.IndexOf(Seperator, currentIndex);
                var objectEndIndex = content.IndexOf('>', currentIndex) - 1;

                // Take the nearest match
                endIndex = Math.Min(andIndex, objectEndIndex);
                if (endIndex < 0)
                {
                    endIndex = Math.Max(andIndex, objectEndIndex);
                }
            }

            if (endIndex < 0)
            {
                throw new InvalidOperationException("Unrecognized format of TCP message content (bad quotation of item parameter value): " + content);
            }

            string value;

            if (endIndex > currentIndex)
            {
                value = XmlEscaper.Unescape(content.Substring(currentIndex, endIndex - currentIndex));
            }
            else if (quoted)
            {
                value = string.Empty;
            }
            else
            {
                value = null;
            }

            currentIndex = endIndex;

            if (quoted || value == null)
            {
                currentIndex++;
            }

            return(new KeyValuePair <string, string>(key, value));
        }