当前位置: 首页>>代码示例>>C#>>正文


C# XmlReader.LookupNamespace方法代码示例

本文整理汇总了C#中System.Xml.XmlReader.LookupNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# XmlReader.LookupNamespace方法的具体用法?C# XmlReader.LookupNamespace怎么用?C# XmlReader.LookupNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.XmlReader的用法示例。


在下文中一共展示了XmlReader.LookupNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ParseQName

        public static XmlQualifiedName ParseQName(string prefixedQName, XmlReader reader)
        {
            Fx.Assert(prefixedQName != null, "The prefixedQName must be non null.");
            Fx.Assert(reader != null, "The reader must be non null.");
            int index = prefixedQName.IndexOf(':');

            string ns;
            string localname;
            if (index != -1)
            {
                string prefix = prefixedQName.Substring(0, index);
                ns = reader.LookupNamespace(prefix);
                if (ns == null)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlQNamePrefixNotDefined(prefix, prefixedQName)));
                }
                localname = prefixedQName.Substring(index + 1);
                if (localname == string.Empty)
                {
                    throw FxTrace.Exception.AsError(new XmlException(SR2.DiscoveryXmlQNameLocalnameNotDefined(prefixedQName)));
                }
            }
            else
            {
                ns = string.Empty;
                localname = prefixedQName;
            }

            localname = XmlConvert.DecodeName(localname);
            return new XmlQualifiedName(localname, ns);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:31,代码来源:SerializationUtility.cs

示例2: ToXName

        internal static XName ToXName(this string self, XmlReader reader)
        {
            var i = self.IndexOf(':');
            if (i == 0 || i == self.Length - 1)
            {
                throw new XmlException($"\"{self}\" is not QName.");
            }

            var prefix = string.Empty;
            var localPart = string.Empty;

            if (i < 0)
            {
                localPart = self;
            }
            else
            {
                prefix = self.Substring(0, i);
                localPart = self.Substring(i + 1);
            }

            XNamespace ns = reader.LookupNamespace(prefix);
            if (ns == null)
            {
                throw new XmlException($"The prefix \"{prefix}\" is not declared.");
            }

            return ns + localPart;
        }
开发者ID:kei10in,项目名称:KipSharp,代码行数:29,代码来源:XmlUtils.cs

示例3: ResolveQName

 public static XmlQualifiedName ResolveQName(XmlReader reader, string qstring)
 {
     string name = qstring;
     string prefix = string.Empty;
     int index = qstring.IndexOf(':');
     if (index > -1)
     {
         prefix = qstring.Substring(0, index);
         name = qstring.Substring(index + 1, qstring.Length - (index + 1));
     }
     return new XmlQualifiedName(name, reader.LookupNamespace(prefix));
 }
开发者ID:gtkrug,项目名称:gfipm-ws-ms.net,代码行数:12,代码来源:XmlUtil.cs

示例4: GetElementTypeInfo

 protected override ITypeSerializationInfo GetElementTypeInfo(XmlReader reader, IPropertySerializationInfo property)
 {
     string attr = reader.GetAttribute(TypeField, XMLSchemaInstanceNamespace);
     if (attr != null)
     {
         int separator = attr.IndexOf(':');
         if (separator == -1) return GetTypeInfo(string.Empty, attr);
         var prefix = attr.Substring(0, separator);
         var localName = attr.Substring(separator + 1);
         return GetTypeInfo(reader.LookupNamespace(prefix), localName);
     }
     else
     {
         if (property.PropertyType.IsCollection)
         {
             return property.PropertyType.CollectionItemType;
         }
         else
         {
             return property.PropertyType;
         }
     }
 }
开发者ID:FrederikP,项目名称:NMF,代码行数:23,代码来源:XmiSerializer.cs

示例5: ParseQName

 public static void ParseQName(XmlReader reader, string qname, out string localName, out string ns)
 {
     int index = qname.IndexOf(':');
     string prefix;
     if (index < 0)
     {
         prefix = "";
         localName = TrimStart(TrimEnd(qname));
     }
     else
     {
         if (index == qname.Length - 1)
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidXmlQualifiedName, qname)));
         prefix = TrimStart(qname.Substring(0, index));
         localName = TrimEnd(qname.Substring(index + 1));
     }
     ns = reader.LookupNamespace(prefix);
     if (ns == null)
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.UnboundPrefixInQName, qname)));
 }
开发者ID:weshaggard,项目名称:wcf,代码行数:20,代码来源:XmlUtil.cs

示例6: ResolveQName

        public static XmlQualifiedName ResolveQName(XmlReader reader, string qstring)
        {
            string name = qstring;
            string prefix = String.Empty;
            string ns = null;

            int colon = qstring.IndexOf(':'); // index of char is always ordinal
            if (colon > -1)
            {
                prefix = qstring.Substring(0, colon);
                name = qstring.Substring(colon + 1, qstring.Length - (colon + 1));
            }

            ns = reader.LookupNamespace(prefix);

            return new XmlQualifiedName(name, ns);
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:17,代码来源:XmlUtil.cs

示例7: ReadFaultCode

 private XmlQualifiedName ReadFaultCode(XmlReader reader) {
     if (reader.IsEmptyElement) {
         reader.Skip();
         return null;
     }
     reader.ReadStartElement();
     string qnameValue = reader.ReadString();
     int colon = qnameValue.IndexOf(":", StringComparison.Ordinal);
     string ns = reader.NamespaceURI;
     if (colon >= 0) {
         string prefix = qnameValue.Substring(0, colon);
         ns = reader.LookupNamespace(prefix);
         if (ns == null)
             throw new InvalidOperationException(Res.GetString(Res.WebQNamePrefixUndefined, prefix));
     }
     reader.ReadEndElement();
     
     return new XmlQualifiedName(qnameValue.Substring(colon + 1), ns);
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:19,代码来源:SoapClientProtocol.cs

示例8: EmptyElementInDefaultNamespace

		public void EmptyElementInDefaultNamespace (XmlReader xmlReader)
		{
			AssertStartDocument (xmlReader);

			AssertNode (
				xmlReader, // xmlReader
				XmlNodeType.Element, // nodeType
				0, // depth
				true, // isEmptyElement
				"foo", // name
				String.Empty, // prefix
				"foo", // localName
				"http://foo/", // namespaceURI
				String.Empty, // value
				1 // attributeCount
			);

			AssertAttribute (
				xmlReader, // xmlReader
				"xmlns", // name
				String.Empty, // prefix
				"xmlns", // localName
				"http://www.w3.org/2000/xmlns/", // namespaceURI
				"http://foo/" // value
			);

			Assert.AreEqual ("http://foo/", xmlReader.LookupNamespace (String.Empty));

			AssertEndDocument (xmlReader);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:30,代码来源:XmlReaderCommonTests.cs

示例9: ValidateNamespace

		public static bool ValidateNamespace(XmlReader reader, string value, string ns)
		{
			char[] chrArray = new char[1];
			chrArray[0] = ':';
			string[] strArrays = value.Split(chrArray);
			if ((int)strArrays.Length != 1)
			{
				string str = strArrays[0];
				return string.Equals(reader.LookupNamespace(str), ns, StringComparison.Ordinal);
			}
			else
			{
				return 0 == reader.NamespaceURI.CompareTo(ns);
			}
		}
开发者ID:nickchal,项目名称:pash,代码行数:15,代码来源:XmlUtility.cs

示例10: Parse

		public static DirectorySearchRequest Parse(XmlReader reader)
		{
			DirectorySearchRequest request = new DirectorySearchRequest();

			reader.MoveToContent();

			if (reader.LocalName != @"Envelope" || reader.LookupNamespace(reader.Prefix) != @"http://schemas.xmlsoap.org/soap/envelope/")
				throw new XmlException();

			reader.Read();
			reader.MoveToElement();

			if (reader.LocalName != @"Body")
				throw new XmlException();

			reader.Read();
			reader.MoveToElement();

			const string schema2 = @"http://schemas.microsoft.com/winrtc/2002/11/sip";
			if (reader.LocalName != @"directorySearch" || reader.LookupNamespace(reader.Prefix) != schema2)
				throw new XmlException();

			reader.Read();
			reader.MoveToElement();
			if (reader.LocalName != @"filter")
				throw new XmlException();
			string filter = reader.GetAttribute(@"href", schema2);

			reader.Read();
			reader.MoveToElement();
			request.MaxResults = reader.ReadElementContentAsInt(@"maxResults", schema2);

			reader.Read();
			reader.MoveToElement();
			if (reader.LocalName != @"Array") 
				throw new XmlException();
			string id = reader.GetAttribute(@"id", schema2);
			if (filter[0] != '#' || filter.Substring(1) != id)
				throw new XmlException();

			reader.Read();
			reader.MoveToElement();
			string z = reader.GetAttribute(@"value");
			while (reader.LocalName == @"row")
			{
				string attrib = reader.GetAttribute(@"attrib", schema2);
				string value = reader.GetAttribute(@"value", schema2);

				if (string.IsNullOrEmpty(attrib) == false)
				{
					if (request.SearchTerms.ContainsKey(attrib))
						request.SearchTerms[attrib] = value;
					else
						request.SearchTerms.Add(attrib, value);
				}

				reader.Read();
				reader.MoveToElement();
			}

			reader.MoveToContent();
			reader.ReadEndElement();

			return request;
		}
开发者ID:hungdluit,项目名称:sipserver,代码行数:65,代码来源:DirectorySearchRequest.cs

示例11: LookupEmptyPrefix

		void LookupEmptyPrefix (XmlReader xmlReader)
		{
			xmlReader.Read ();
			Assert.IsNull (xmlReader.LookupNamespace (String.Empty));
		}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:XmlReaderCommonTests.cs

示例12: ValidateXsiType

        // This method validates xsi:type="dcterms:W3CDTF"
        // The valude of xsi:type is a qualified name. It should have a prefix that matches
        //  the xml namespace (ns) within the scope and the name that matches name
        // The comparisons should be case-sensitive comparisons
        internal static void ValidateXsiType(XmlReader reader, Object ns, string name)
        {
            // Get the value of xsi;type
            String typeValue = reader.GetAttribute(PackageXmlStringTable.GetXmlString(PackageXmlEnum.Type),
                                PackageXmlStringTable.GetXmlString(PackageXmlEnum.XmlSchemaInstanceNamespace));

            // Missing xsi:type
            if (typeValue == null)
            {
                throw new XmlException(SR.Format(SR.UnknownDCDateTimeXsiType, reader.Name),
                    null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition);
            }

            int index = typeValue.IndexOf(':');

            // The valude of xsi:type is not a qualified name
            if (index == -1)
            {
                throw new XmlException(SR.Format(SR.UnknownDCDateTimeXsiType, reader.Name),
                    null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition);
            }

            // Check the following conditions
            //  The namespace of the prefix (string before ":") matches "ns"
            //  The name (string after ":") matches "name"
            if (!Object.ReferenceEquals(ns, reader.LookupNamespace(typeValue.Substring(0, index)))
                    || String.CompareOrdinal(name, typeValue.Substring(index + 1, typeValue.Length - index - 1)) != 0)
            {
                throw new XmlException(SR.Format(SR.UnknownDCDateTimeXsiType, reader.Name),
                    null, ((IXmlLineInfo)reader).LineNumber, ((IXmlLineInfo)reader).LinePosition);
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:36,代码来源:PartBasedPackageProperties.cs

示例13: Deserialize

		// This method handles z:Ref, xsi:nil and primitive types, and then delegates to DeserializeByMap() for anything else.

		public object Deserialize (Type type, XmlReader reader)
		{
#if !MOONLIGHT
			if (type == typeof (XmlElement))
				return XmlDocument.ReadNode (reader);
			else if (type == typeof (XmlNode [])) {
				reader.ReadStartElement ();
				var l = new List<XmlNode> ();
				for(; !reader.EOF && reader.NodeType != XmlNodeType.EndElement; reader.MoveToContent ())
					l.Add (XmlDocument.ReadNode (reader));
				reader.ReadEndElement ();
				return l.ToArray ();
			}
#endif
			QName graph_qname = null;
			
			if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>)) {
				Type internal_type = type.GetGenericArguments () [0];
				
				if (types.FindUserMap(internal_type) != null) {
					graph_qname = types.GetQName (internal_type);
				}
			}
			
			if (graph_qname == null)
				graph_qname = types.GetQName (type);
				
			string itype = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
			if (itype != null) {
				string [] parts = itype.Split (':');
				if (parts.Length > 1)
					graph_qname = new QName (parts [1], reader.LookupNamespace (reader.NameTable.Get (parts [0])));
				else
					graph_qname = new QName (itype, reader.LookupNamespace (String.Empty));
			}

			string label = reader.GetAttribute ("Ref", KnownTypeCollection.MSSimpleNamespace);
			if (label != null) {
				object o;
				if (!references.TryGetValue (label, out o))
					throw new SerializationException (String.Format ("Deserialized object with reference Id '{0}' was not found", label));
				reader.Skip ();
				return o;
			}

			bool isNil = reader.GetAttribute ("nil", XmlSchema.InstanceNamespace) == "true";

			if (isNil) {
				reader.Skip ();
				if (!type.IsValueType || type == typeof (void))
					return null;
				else if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>))
					return null;
				else 
					throw new SerializationException (String.Format ("Value type {0} cannot be null.", type));
			}

			if (resolver != null) {
				Type t;
				if (resolved_qnames.TryGetValue (graph_qname, out t))
					type = t;
				else { // i.e. resolve name only once.
					type = resolver.ResolveName (graph_qname.Name, graph_qname.Namespace, type, default_resolver) ?? type;
					resolved_qnames.Add (graph_qname, type);
					types.Add (type);
				}
			}

			if (KnownTypeCollection.GetPrimitiveTypeFromName (graph_qname) != null) {
				string id = reader.GetAttribute ("Id", KnownTypeCollection.MSSimpleNamespace);

				object ret = DeserializePrimitive (type, reader, graph_qname);

				if (id != null) {
					if (references.ContainsKey (id))
						throw new InvalidOperationException (String.Format ("Object with Id '{0}' already exists as '{1}'", id, references [id]));
					references.Add (id, ret);
				}
				return ret;
			}

			return DeserializeByMap (graph_qname, type, reader);
		}
开发者ID:nestalk,项目名称:mono,代码行数:85,代码来源:XmlFormatterDeserializer.cs

示例14: ExpandXmlNamespaces

 private string ExpandXmlNamespaces(XmlReader input, string typeName)
 {
     int startIndex = 0;
     int num;
     while ((num = typeName.IndexOf(':', startIndex)) > 0)
     {
         int num2 = typeName.LastIndexOfAny(this.XmlNamespaceBeginnings, num) + 1;
         string text = typeName.Substring(0, num2);
         string text2 = typeName.Substring(num2, num - num2);
         string text3 = typeName.Substring(num + 1);
         text2 = input.LookupNamespace(text2);
         typeName = string.Concat(new object[]
         {
             text,
             text2,
             '.',
             text3
         });
         startIndex = typeName.Length - text3.Length;
     }
     return typeName;
 }
开发者ID:KingpinBen,项目名称:Spin-Doctor,代码行数:22,代码来源:TypeNameHelper.cs

示例15: DeserializeCore

		public object DeserializeCore (Type type, XmlReader reader)
		{
			QName graph_qname = types.GetQName (type);
			string itype = reader.GetAttribute ("type", XmlSchema.InstanceNamespace);
			if (itype != null) {
				string[] parts = itype.Split (':');
				if (parts.Length > 1)
					graph_qname = new QName (parts [1], reader.LookupNamespace (reader.NameTable.Get (parts[0])));
				else
					graph_qname = new QName (itype, reader.NamespaceURI);
			}

			string label = reader.GetAttribute ("Ref", KnownTypeCollection.MSSimpleNamespace);
			if (label != null) {
				object o = references [label];
				if (o == null)
					throw new SerializationException (String.Format ("Deserialized object with reference Id '{0}' was not found", label));
				reader.Skip ();
				return o;
			}

			bool isNil = reader.GetAttribute ("nil", XmlSchema.InstanceNamespace) == "true";

			if (isNil) {
				reader.Skip ();
				if (!type.IsValueType)
					return null;
				else if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>))
					return null;
				else 
					throw new SerializationException (String.Format ("Value type {0} cannot be null.", type));
			}

			if (KnownTypeCollection.GetPrimitiveTypeFromName (graph_qname.Name) != null) {
				string value;
				if (reader.IsEmptyElement) {
					reader.Read (); // advance
					if (type.IsValueType)
						return Activator.CreateInstance (type);
					else
						// FIXME: Workaround for creating empty objects of the correct type.
						value = String.Empty;
				}
				else
					value = reader.ReadElementContentAsString ();
				return KnownTypeCollection.PredefinedTypeStringToObject (value, graph_qname.Name, reader);
			}

			return DeserializeByMap (graph_qname, type, reader);
		}
开发者ID:stabbylambda,项目名称:mono,代码行数:50,代码来源:XmlFormatterDeserializer.cs


注:本文中的System.Xml.XmlReader.LookupNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。