LookupNamespace() public abstract method

public abstract LookupNamespace ( string prefix ) : string
prefix string
return string
Example #1
0
        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;
        }
        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);
        }
Example #3
0
 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));
 }
Example #4
0
 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;
         }
     }
 }
Example #5
0
		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);
		}
Example #6
0
		void LookupEmptyPrefix (XmlReader xmlReader)
		{
			xmlReader.Read ();
			Assert.IsNull (xmlReader.LookupNamespace (String.Empty));
		}
		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;
		}
Example #8
0
		internal static XmlQualifiedName Parse (string name, XmlReader reader)
		{
			int index = name.IndexOf (':');
			if (index < 0)
				return new XmlQualifiedName (name);
			string ns = reader.LookupNamespace (name.Substring (0, index));
			if (ns == null)
				throw new ArgumentException ("Invalid qualified name.");
			return new XmlQualifiedName (name.Substring (index + 1), ns);
		}
 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);
 }
        /// <summary>
        /// override of GetElementType
        /// </summary>
        public override bool GetElementType(
                XmlReader   xmlReader,
                string      localName,
                string      namespaceUri,
            ref string      assemblyName,
            ref string      typeFullName,
            ref Type        baseType,
            ref Type        serializerType)
        {
            if (!ProcessedRootElement &&
                namespaceUri.Equals(XamlReaderHelper.DefinitionNamespaceURI) &&
                (localName.Equals(XamlReaderHelper.DefinitionCodeTag) ||
                 localName.Equals(XamlReaderHelper.DefinitionXDataTag)))
            {
                MarkupCompiler.ThrowCompilerException(SRID.DefinitionTagNotAllowedAtRoot,
                                                      xmlReader.Prefix,
                                                      localName);
            }

            bool foundElement = base.GetElementType(xmlReader, localName, namespaceUri, 
                ref assemblyName, ref typeFullName, ref baseType, ref serializerType);

            if (!ProcessedRootElement)
            {
                int count = xmlReader.AttributeCount;

                // save reader's position, to be restored later
                string attrName = (xmlReader.NodeType == XmlNodeType.Attribute) ? xmlReader.Name : null;

                _isRootTag = true;
                _class = string.Empty;
                _subClass = string.Empty;
                ProcessedRootElement = true;
                XamlTypeMapper.IsProtectedAttributeAllowed = false;
                xmlReader.MoveToFirstAttribute();

                while (--count >= 0)
                {
                    string attribNamespaceURI = xmlReader.LookupNamespace(xmlReader.Prefix);

                    if (attribNamespaceURI != null &&
                        attribNamespaceURI.Equals(XamlReaderHelper.DefinitionNamespaceURI))
                    {
                        MarkupCompiler.DefinitionNSPrefix = xmlReader.Prefix;

                        if (xmlReader.LocalName == CLASS)
                        {
                            _class = xmlReader.Value.Trim();
                            if (_class == string.Empty)
                            {
                                // flag an error for processing later in WriteDefAttribute
                                _class = MarkupCompiler.DOT;
                            }
                            else
                            {
                                // flag this so that the Type Mapper can allow protected
                                // attributes on the markup sub-classed root element only.
                                XamlTypeMapper.IsProtectedAttributeAllowed = true;
                            }
                        }
                        else if (xmlReader.LocalName == XamlReaderHelper.DefinitionTypeArgs)
                        {
                            string genericName = _compiler.GetGenericTypeName(localName, xmlReader.Value);

                            foundElement = base.GetElementType(xmlReader, genericName, namespaceUri,
                                ref assemblyName, ref typeFullName, ref baseType, ref serializerType);

                            if (!foundElement)
                            {
                                NamespaceMapEntry[] namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(namespaceUri);
                                bool isLocal = namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly;
                                if (!isLocal)
                                {
                                    MarkupCompiler.ThrowCompilerException(SRID.UnknownGenericType,
                                                                          MarkupCompiler.DefinitionNSPrefix,
                                                                          xmlReader.Value,
                                                                          localName);
                                }
                            }
                        }
                        else if (xmlReader.LocalName == SUBCLASS)
                        {
                            _subClass = xmlReader.Value.Trim();
                            if (_subClass == string.Empty)
                            {
                                // flag an error for processing later in WriteDefAttribute
                                _subClass = MarkupCompiler.DOT;
                            }
                            else
                            {
                                _compiler.ValidateFullSubClassName(ref _subClass);
                            }
                        }
                        else if (xmlReader.LocalName == CLASSMODIFIER)
                        {
                            if (!_pass2)
                            {
                                _classModifier = xmlReader.Value.Trim();
                                if (_classModifier == string.Empty)
                                {
                                    // flag an error for processing later in WriteDefAttribute
                                    _classModifier = MarkupCompiler.DOT;
                                }
                            }
                            else
                            {
                                // This direct comparison is ok to do in pass2 as it has already been validated in pass1.
                                // This is to avoid a costly instantiation of the CodeDomProvider in pass2.
                                _isInternalRoot = string.Compare("public", xmlReader.Value.Trim(), StringComparison.OrdinalIgnoreCase) != 0;
                            }
                        }
                    }

                    xmlReader.MoveToNextAttribute();
                }

                if (namespaceUri.Equals(XamlReaderHelper.DefinitionNamespaceURI))
                {
                    xmlReader.MoveToElement();
                }
                else
                {
                    if (attrName == null)
                        xmlReader.MoveToFirstAttribute();
                    else
                        xmlReader.MoveToAttribute(attrName);
                }
            }
            else if (!_compiler.IsBamlNeeded && !_compiler.ProcessingRootContext && _compiler.IsCompilingEntryPointClass && xmlReader.Depth > 0)
            {
                if ((!localName.Equals(MarkupCompiler.CODETAG) &&
                     !localName.Equals(MarkupCompiler.CODETAG + "Extension")) ||
                    !namespaceUri.Equals(XamlReaderHelper.DefinitionNamespaceURI))
                {
                    _compiler.IsBamlNeeded = true;
                }
            }

            return foundElement;
        }
Example #11
0
        // this method can run on a worker thread! 
        private void CreateDocFromInlineXml(XmlReader xmlReader)
        { 
            // Maybe things have changed and we don't want to use inline doc anymore 
            if (!_tryInlineDoc)
            { 
                _savedDocument = null;
                if (_waitForInlineDoc != null)
                    _waitForInlineDoc.Set();
                return; 
            }
 
            XmlDocument doc; 
            Exception ex = null;
 
            try
            {
                doc = new XmlDocument();
                try 
                {
                    if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.XmlProvider)) 
                    { 
                        TraceData.Trace(TraceEventType.Warning,
                                            TraceData.XmlLoadInline( 
                                                TraceData.Identify(this),
                                                Dispatcher.CheckAccess() ? "synchronous" : "asynchronous"));
                    }
 
                    // Load the inline doc from the reader
                    doc.Load(xmlReader); 
                } 
                catch (XmlException xmle)
                { 
                    if (TraceData.IsEnabled)
                        TraceData.Trace(TraceEventType.Error, TraceData.XmlDPInlineDocError, xmle);
                    ex = xmle;
                } 

                if (ex == null) 
                { 
                    // Save a copy of the inline document to be used in future
                    // queries, and by serialization. 
                    _savedDocument = (XmlDocument)doc.Clone();
                }
            }
            finally 
            {
                xmlReader.Close(); 
                // Whether or not parsing was successful, unblock the serializer thread. 

                // If serializer had to wait for the inline doc, it's available now. 
                // If there was an error, null will be returned for DocumentForSerialization.
                if (_waitForInlineDoc != null)
                    _waitForInlineDoc.Set();
            } 

            // warn the user if the default xmlns wasn't set explicitly (bug 1006946) 
            if (TraceData.IsEnabled) 
            {
                XmlNode root = doc.DocumentElement; 
                if (root != null && root.NamespaceURI == xmlReader.LookupNamespace(String.Empty))
                {
                    TraceData.Trace(TraceEventType.Error, TraceData.XmlNamespaceNotSet);
                } 
            }
 
            if (ex == null) 
            {
                // Load succeeded.  Create the node collection.  (This calls 
                // OnQueryFinished to reset the Document and Data properties).
                BuildNodeCollection(doc);
            }
            else 
            {
                if (TraceData.IsExtendedTraceEnabled(this, TraceDataLevel.ProviderQuery)) 
                { 
                    TraceData.Trace(TraceEventType.Warning,
                                        TraceData.QueryFinished( 
                                            TraceData.Identify(this),
                                            Dispatcher.CheckAccess() ? "synchronous" : "asynchronous",
                                            TraceData.Identify(null),
                                            TraceData.IdentifyException(ex))); 
                }
 
                // Load failed.  Report the error, and reset 
                // Data and Document properties to null.
                OnQueryFinished(null, ex, CompletedCallback, null); 
            }
        }
Example #12
0
 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;
 }
Example #13
0
 private static void CompareReaderProperties(XmlReader standard, XmlReader custom)
 {
     Assert.AreEqual(standard.AttributeCount, custom.AttributeCount);
     Assert.AreEqual(standard.BaseURI, custom.BaseURI);
     Assert.AreEqual(standard.Depth, custom.Depth);
     Assert.AreEqual(standard.EOF, custom.EOF);
     Assert.AreEqual(standard.HasAttributes, custom.HasAttributes);
     Assert.AreEqual(standard.HasValue, custom.HasValue);
     Assert.AreEqual(standard.IsDefault, custom.IsDefault);
     Assert.AreEqual(standard.IsEmptyElement, custom.IsEmptyElement);
     Assert.AreEqual(standard.LocalName, custom.LocalName);
     Assert.AreEqual(standard.Name, custom.Name);
     Assert.AreEqual(standard.NamespaceURI, custom.NamespaceURI);
     Assert.AreEqual(standard.NodeType, custom.NodeType);
     Assert.AreEqual(standard.Prefix, custom.Prefix);
     Assert.AreEqual(standard.QuoteChar, custom.QuoteChar);
     Assert.AreEqual(standard.ReadState, custom.ReadState);
     Assert.AreEqual(standard.Value, custom.Value);
     Assert.AreEqual(standard.ValueType, custom.ValueType);
     Assert.AreEqual(standard.XmlLang, custom.XmlLang);
     Assert.AreEqual(standard.XmlSpace, custom.XmlSpace);
     Assert.AreEqual(standard.LookupNamespace("foo"), custom.LookupNamespace("foo"));            
 }
Example #14
0
 public XmlReader(IFormatReaderContext context, System.Xml.XmlReader reader)
     : this(context, reader, reader.LookupNamespace(string.Empty))
 {
 }
Example #15
0
		internal static XmlQualifiedName Parse (string name, XmlReader reader, bool considerDefaultNamespace)
		{
			int index = name.IndexOf (':');
			if (index < 0 && !considerDefaultNamespace)
				return new XmlQualifiedName (name);
			string ns = reader.LookupNamespace (index < 0 ? String.Empty : name.Substring (0, index));
			if (ns == null && index > 0)
				throw new ArgumentException ("Invalid qualified name.");
			return new XmlQualifiedName (index < 0 ? name : name.Substring (index + 1), ns);
		}
Example #16
0
 public override string LookupNamespace(string prefix)
 {
     CheckAsync();
     return(_coreReader.LookupNamespace(prefix));
 }
Example #17
0
		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);
			}
		}
 /// <summary>checks to see if the passed in namespace is the current one</summary> 
 /// <param name="reader">correctly positioned xmlreader</param>
 /// <param name="namespaceToCompare">the namespace to test for</param> 
 /// <returns> true if this is the one</returns>
 static protected bool IsCurrentNameSpace(XmlReader reader, string namespaceToCompare) {
     Tracing.Assert(reader != null, "reader should not be null");
     if (reader == null) {
         throw new ArgumentNullException("reader");
     }
     string curNamespace = reader.NamespaceURI;
     if (curNamespace.Length == 0) {
         curNamespace = reader.LookupNamespace(String.Empty);
     }
     return curNamespace == namespaceToCompare;
 }
Example #19
0
		static void ParseWsdlArrayType (XmlReader reader, XmlAttribute attr)
		{
			if (attr.NamespaceURI == XmlSerializer.WsdlNamespace && attr.LocalName == "arrayType")
			{
				string ns = "", type, dimensions;
				TypeTranslator.ParseArrayType (attr.Value, out type, out ns, out dimensions);
				if (ns != "") ns = reader.LookupNamespace (ns) + ":";
				attr.Value = ns + type + dimensions;
			}
		}
Example #20
0
        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);
        }
Example #21
0
		//While Creating a XmlQualifedName, we should check:
		// 1. If a prefix is present, its namespace should be resolvable.
		// 2. If a prefix is not present, and if the defaultNamespace is set, 
		public static XmlQualifiedName ToQName(XmlReader reader, string qnamestr, out Exception innerEx)
		{

			string ns;
			string name;
			XmlQualifiedName qname;
			innerEx = null;
			
			if(!IsValidQName(qnamestr))
			{
				innerEx = new Exception(qnamestr + " is an invalid QName. Either name or namespace is not a NCName");
				return XmlQualifiedName.Empty;
			}

			string[] values = qnamestr.Split(new char[]{':'},2);

			if(values.Length == 2)
			{
				ns = reader.LookupNamespace(values[0]);
				if(ns == null)
				{
					innerEx = new Exception("Namespace Prefix '"+values[0]+"could not be resolved");
					return XmlQualifiedName.Empty;
				}
				name = values[1];
			}
			else
			{
				//Default Namespace
				ns = reader.LookupNamespace("");
				name = values[0];
			}

			qname = new XmlQualifiedName(name,ns);
			return qname;
		}
Example #22
0
 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)));
 }
        /// <summary>
        /// Reads the &lt;saml:Attribute> element.
        /// </summary>
        /// <remarks>
        /// The default implementation requires that the content of the 
        /// Attribute element be a simple string. To handle complex content
        /// or content of declared simple types other than xs:string, override
        /// this method.
        /// </remarks>
        /// <param name="reader">An <see cref="XmlReader"/> positioned at a <see cref="Saml2Attribute"/> element.</param>
        /// <returns>A <see cref="Saml2Attribute"/> instance.</returns>
        protected virtual Saml2Attribute ReadAttribute(XmlReader reader)
        {
            if (null == reader)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
            }

            // throw if wrong element
            if (!reader.IsStartElement(Saml2Constants.Elements.Attribute, Saml2Constants.Namespace))
            {
                reader.ReadStartElement(Saml2Constants.Elements.Attribute, Saml2Constants.Namespace);
            }

            try
            {
                Saml2Attribute attribute;
                bool isEmpty = reader.IsEmptyElement;

                // @attributes
                string value;

                // @xsi:type 
                XmlUtil.ValidateXsiType(reader, Saml2Constants.Types.AttributeType, Saml2Constants.Namespace);

                // @Name - required
                value = reader.GetAttribute(Saml2Constants.Attributes.Name);
                if (string.IsNullOrEmpty(value))
                {
                    throw DiagnosticUtility.ThrowHelperXml(reader, SR.GetString(SR.ID0001, Saml2Constants.Attributes.Name, Saml2Constants.Elements.Attribute));
                }

                attribute = new Saml2Attribute(value);

                // @NameFormat - optional
                value = reader.GetAttribute(Saml2Constants.Attributes.NameFormat);
                if (!string.IsNullOrEmpty(value))
                {
                    if (!UriUtil.CanCreateValidUri(value, UriKind.Absolute))
                    {
                        throw DiagnosticUtility.ThrowHelperXml(reader, SR.GetString(SR.ID0011, Saml2Constants.Attributes.Namespace, Saml2Constants.Elements.Action));
                    }

                    attribute.NameFormat = new Uri(value);
                }

                // @FriendlyName - optional
                attribute.FriendlyName = reader.GetAttribute(Saml2Constants.Attributes.FriendlyName);

                // @OriginalIssuer - optional.
                // We are lax on read here, and will accept the following namespaces for original issuer, in order:
                // http://schemas.xmlsoap.org/ws/2009/09/identity/claims
                // http://schemas.microsoft.com/ws/2008/06/identity
                string originalIssuer = reader.GetAttribute(Saml2Constants.Attributes.OriginalIssuer, ClaimType2009Namespace);

                if (originalIssuer == null)
                {
                    originalIssuer = reader.GetAttribute(Saml2Constants.Attributes.OriginalIssuer, ProductConstants.NamespaceUri);
                }

                if (originalIssuer == String.Empty)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.ID4252)));
                }

                attribute.OriginalIssuer = originalIssuer;

                // content
                reader.Read();
                if (!isEmpty)
                {
                    while (reader.IsStartElement(Saml2Constants.Elements.AttributeValue, Saml2Constants.Namespace))
                    {
                        bool isEmptyValue = reader.IsEmptyElement;
                        bool isNil = XmlUtil.IsNil(reader);

                        // FIP 9570 - ENTERPRISE SCENARIO: Saml11SecurityTokenHandler.ReadAttribute is not checking the AttributeValue XSI type correctly.
                        // Lax on receive. If we dont find the AttributeValueXsiType in the format we are looking for in the xml, we default to string.
                        // Read the xsi:type. We are expecting a value of the form "some-non-empty-string" or "some-non-empty-local-prefix:some-non-empty-string".
                        // ":some-non-empty-string" and "some-non-empty-string:" are edge-cases where defaulting to string is reasonable.
                        // For attributeValueXsiTypeSuffix, we want the portion after the local prefix in "some-non-empty-local-prefix:some-non-empty-string"
                        // "some-non-empty-local-prefix:some-non-empty-string" case
                        string attributeValueXsiTypePrefix = null;
                        string attributeValueXsiTypeSuffix = null;
                        string attributeValueXsiTypeSuffixWithLocalPrefix = reader.GetAttribute("type", XmlSchema.InstanceNamespace);
                        if (!string.IsNullOrEmpty(attributeValueXsiTypeSuffixWithLocalPrefix))
                        {
                            // "some-non-empty-string" case
                            if (attributeValueXsiTypeSuffixWithLocalPrefix.IndexOf(":", StringComparison.Ordinal) == -1)
                            {
                                attributeValueXsiTypePrefix = reader.LookupNamespace(String.Empty);
                                attributeValueXsiTypeSuffix = attributeValueXsiTypeSuffixWithLocalPrefix;
                            }
                            else if (attributeValueXsiTypeSuffixWithLocalPrefix.IndexOf(":", StringComparison.Ordinal) > 0 &&
                                      attributeValueXsiTypeSuffixWithLocalPrefix.IndexOf(":", StringComparison.Ordinal) < attributeValueXsiTypeSuffixWithLocalPrefix.Length - 1)
                            {
                                string localPrefix = attributeValueXsiTypeSuffixWithLocalPrefix.Substring(0, attributeValueXsiTypeSuffixWithLocalPrefix.IndexOf(":", StringComparison.Ordinal));
                                attributeValueXsiTypePrefix = reader.LookupNamespace(localPrefix);
                                attributeValueXsiTypeSuffix = attributeValueXsiTypeSuffixWithLocalPrefix.Substring(attributeValueXsiTypeSuffixWithLocalPrefix.IndexOf(":", StringComparison.Ordinal) + 1);
                            }
                        }

                        if (attributeValueXsiTypePrefix != null && attributeValueXsiTypeSuffix != null)
                        {
                            attribute.AttributeValueXsiType = String.Concat(attributeValueXsiTypePrefix, "#", attributeValueXsiTypeSuffix);
                        }

                        if (isNil)
                        {
                            reader.Read();
                            if (!isEmptyValue)
                            {
                                reader.ReadEndElement();
                            }

                            attribute.Values.Add(null);
                        }
                        else if (isEmptyValue)
                        {
                            reader.Read();
                            attribute.Values.Add(string.Empty);
                        }
                        else
                        {
                            attribute.Values.Add(this.ReadAttributeValue(reader, attribute));
                        }
                    }

                    reader.ReadEndElement();
                }

                return attribute;
            }
            catch (Exception e)
            {
                if (System.Runtime.Fx.IsFatal(e))
                    throw;
                
                Exception wrapped = TryWrapReadException(reader, e);
                if (null == wrapped)
                {
                    throw;
                }
                else
                {
                    throw wrapped;
                }
            }
        }
 internal DpwsServiceType(String type, XmlReader context)
 {
     // Check to see if this is a fully qualified path. If so parse into namespaceUri and typeName.
     if (Uri.IsWellFormedUriString(type, UriKind.Absolute) && type.LastIndexOf("/") != -1)
     {
         int typeNameIndex = type.LastIndexOf("/");
         NamespaceUri = type.Substring(typeNameIndex);
         TypeName = type.Substring(typeNameIndex + 1);
     }
     else
     {
         int prefixIndex;
         if ((prefixIndex = type.IndexOf(':')) > 0)
         {
             NamespaceUri = context.LookupNamespace(type.Substring(0, prefixIndex));
             TypeName = type.Substring(prefixIndex + 1);
         }
         else
         {
             TypeName = type;
         }
     }
 }
		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);
		}
Example #26
0
		public void AttributeInNamespace (XmlReader xmlReader)
		{
			AssertStartDocument (xmlReader);

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

			AssertAttribute (
				xmlReader, // xmlReader
				"bar:baz", // name
				"bar", // prefix
				"baz", // localName
				"http://bar/", // namespaceURI
				"quux" // value
			);

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

			Assert.AreEqual ("http://bar/", xmlReader.LookupNamespace ("bar"));

			AssertEndDocument (xmlReader);
		}
        // 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);
            }
        }
Example #28
0
		void LookupNamespaceAtEndElement (XmlReader reader)
		{
			reader.Read ();
			Assert.AreEqual ("urn:foo", reader.LookupNamespace ("x"), "#1");
			reader.Read ();
			Assert.AreEqual ("urn:foo", reader.LookupNamespace ("x"), "#2");
			reader.Read ();
			Assert.AreEqual ("urn:foo", reader.LookupNamespace ("x"), "#3");
		}
Example #29
0
		// 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);
		}
Example #30
0
		public void ChildElementInNamespace (XmlReader xmlReader)
		{
			AssertStartDocument (xmlReader);

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

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

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

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

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

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

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

			Assert.AreEqual ("http://foo/", xmlReader.LookupNamespace ("foo"));
			Assert.IsNull (xmlReader.LookupNamespace ("baz"));

			AssertEndDocument (xmlReader);
		}
Example #31
0
 internal static XmlQualifiedName GetValueAsQName(XmlReader reader, string value)
 {
     string prefix;
     string name;
     SplitIntoPrefixAndName(value, out prefix, out name);
     string ns = reader.LookupNamespace(prefix);
     if (ns == null && prefix.Length > 0)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.CouldNotFindNamespaceForPrefix, prefix)));
     }
     return new XmlQualifiedName(name, ns);
 }
        static XmlQualifiedName ParseQName(string lexicalQName, XmlReader reader)
        {
            string[] parts = lexicalQName.Split(':');

             if (parts.Length == 1) {
            return new XmlQualifiedName(parts[0]);
             }

             string prefix = parts[0];
             string ns = reader.LookupNamespace(prefix);

             return new XmlQualifiedName(parts[1], ns);
        }
 // Resolves a namespace prefix in the current element's scope.
 public override string LookupNamespace(string prefix)
 {
     return(coreReader.LookupNamespace(prefix));
 }