Esempio n. 1
0
        public static Literal Parse(string literal, NamespaceManager namespaces)
        {
            if (literal.Length < 2 || literal[0] != '\"')
            {
                throw new FormatException("Literal value must start with a quote.");
            }
            int quote = literal.LastIndexOf('"');

            if (quote <= 0)
            {
                throw new FormatException("Literal value must have an end quote (" + literal + ")");
            }
            string value = literal.Substring(1, quote - 1);

            literal = literal.Substring(quote + 1);

            value = value.Replace("\\\"", "\"");
            value = value.Replace("\\\\", "\\");

            string lang     = null;
            string datatype = null;

            if (literal.Length >= 2 && literal[0] == '@')
            {
                int type = literal.IndexOf("^^");
                if (type == -1)
                {
                    lang = literal.Substring(1);
                }
                else
                {
                    lang    = literal.Substring(1, type);
                    literal = literal.Substring(type);
                }
            }

            if (literal.StartsWith("^^"))
            {
                if (literal.StartsWith("^^<") && literal.EndsWith(">"))
                {
                    datatype = literal.Substring(3, literal.Length - 4);
                }
                else
                {
                    if (namespaces == null)
                    {
                        throw new ArgumentException("No NamespaceManager was given to resolve the QName in the literal string.");
                    }
                    datatype = namespaces.Resolve(literal.Substring(2));
                }
            }

            return(new Literal(value, lang, datatype));
        }
		public static Literal Parse(string literal, NamespaceManager namespaces) {
			if (literal.Length < 2 || literal[0] != '\"') throw new FormatException("Literal value must start with a quote.");
			int quote = literal.LastIndexOf('"');
			if (quote <= 0) throw new FormatException("Literal value must have an end quote (" + literal + ")");
			string value = literal.Substring(1, quote-1);
			literal = literal.Substring(quote+1);
			
			value = value.Replace("\\\"", "\"");
			value = value.Replace("\\\\", "\\");
			
			string lang = null;
			string datatype = null;
			
			if (literal.Length >= 2 && literal[0] == '@') {
				int type = literal.IndexOf("^^");
				if (type == -1) lang = literal.Substring(1);
				else {
					lang = literal.Substring(1, type);
					literal = literal.Substring(type);
				}
			}
			
			if (literal.StartsWith("^^")) {
				if (literal.StartsWith("^^<") && literal.EndsWith(">")) {
					datatype = literal.Substring(3, literal.Length-4);
				} else {
					if (namespaces == null)
						throw new ArgumentException("No NamespaceManager was given to resolve the QName in the literal string.");
					datatype = namespaces.Resolve(literal.Substring(2));
				}
			}
			
			return new Literal(value, lang, datatype);
		}
Esempio n. 3
0
 /// <summary>
 /// Resolves the specified qName.
 /// </summary>
 /// <param name="qname">The qName.</param>
 /// <returns>The resolved URI.</returns>
 public override string Resolve(string qName)
 {
     return(m_OriginalNamespaceManager.Resolve(qName));
 }