Equal() public static method

public static Equal ( string strA, string strB ) : bool
strA string
strB string
return bool
Esempio n. 1
0
 private int GetAttributeIndexWithoutPrefix(string name)
 {
     name = this.coreReaderNameTable.Get(name);
     if (name != null)
     {
         for (int i = 0; i < this.attributeCount; i++)
         {
             ValidatingReaderNodeData data = this.attributeEvents[i];
             if (Ref.Equal(data.LocalName, name) && (data.Prefix.Length == 0))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
Esempio n. 2
0
 private int GetAttributeIndexWithPrefix(string name)
 {
     name = this.coreReaderNameTable.Get(name);
     if (name != null)
     {
         for (int i = 0; i < this.attributeCount; i++)
         {
             ValidatingReaderNodeData data = this.attributeEvents[i];
             if (Ref.Equal(data.GetAtomizedNameWPrefix(this.coreReaderNameTable), name))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.HasNamespace"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual bool HasNamespace(string prefix)
 {
     if (prefix == null)
     {
         return(false);
     }
     for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
     {
         NsDecl decl = (NsDecl)decls[declIndex];
         if (Ref.Equal(decl.Prefix, prefix) && decl.Uri != null)
         {
             return(true);
         }
     }
     return(false);
 }
        // Gets the value of the attribute with the specified LocalName and NamespaceURI.
        public override string GetAttribute(string name, string namespaceURI)
        {
            namespaceURI = (namespaceURI == null) ? string.Empty : coreReaderNameTable.Get(namespaceURI);
            name         = coreReaderNameTable.Get(name);
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < attributeCount; i++)
            {
                attribute = attributeEvents[i];
                if (Ref.Equal(attribute.LocalName, name) && Ref.Equal(attribute.Namespace, namespaceURI))
                {
                    return(attribute.RawValue);
                }
            }
            return(null);
        }
Esempio n. 5
0
 public override bool MoveToAttribute(string name, string ns)
 {
     ns   = (ns == null) ? string.Empty : this.coreReaderNameTable.Get(ns);
     name = this.coreReaderNameTable.Get(name);
     for (int i = 0; i < this.attributeCount; i++)
     {
         ValidatingReaderNodeData data = this.attributeEvents[i];
         if (Ref.Equal(data.LocalName, name) && Ref.Equal(data.Namespace, ns))
         {
             this.currentAttrIndex = i;
             this.cachedNode       = this.attributeEvents[i];
             return(true);
         }
     }
     return(false);
 }
 private void RemoveNamespace(string prefix, string localName)
 {
     for (int i = 0; i < this.nsAttrCount; i++)
     {
         if (Ref.Equal(prefix, this.nsAttributes[i].prefix) && Ref.Equal(localName, this.nsAttributes[i].localName))
         {
             if (i < (this.nsAttrCount - 1))
             {
                 NodeData data = this.nsAttributes[i];
                 this.nsAttributes[i] = this.nsAttributes[this.nsAttrCount - 1];
                 this.nsAttributes[this.nsAttrCount - 1] = data;
             }
             this.nsAttrCount--;
             return;
         }
     }
 }
Esempio n. 7
0
        private void ValidateSingleElement(XmlElement elementNode, bool skipToEnd, XmlSchemaInfo newSchemaInfo)
        {
            _nsManager.PushScope();
            Debug.Assert(elementNode != null);

            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attr       = null;

            //Find Xsi attributes that need to be processed before validating the element
            string xsiNil  = null;
            string xsiType = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attr = attributes[i];
                string objectNs   = attr.NamespaceURI;
                string objectName = attr.LocalName;
                Debug.Assert(_nameTable.Get(attr.NamespaceURI) != null);
                Debug.Assert(_nameTable.Get(attr.LocalName) != null);

                if (Ref.Equal(objectNs, _nsXsi))
                {
                    if (Ref.Equal(objectName, _xsiType))
                    {
                        xsiType = attr.Value;
                    }
                    else if (Ref.Equal(objectName, _xsiNil))
                    {
                        xsiNil = attr.Value;
                    }
                }
                else if (Ref.Equal(objectNs, _nsXmlNs))
                {
                    _nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value);
                }
            }
            _validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, newSchemaInfo, xsiType, xsiNil, null, null);
            //Validate end of element
            if (skipToEnd)
            {
                _validator.ValidateEndOfAttributes(newSchemaInfo);
                _validator.SkipToEndElement(newSchemaInfo);
                _nsManager.PopScope(); //Pop current namespace scope
            }
        }
 private bool IsMatch(XmlNode curNode)
 {
     if (curNode.NodeType == XmlNodeType.Element)
     {
         if (this.name != null)
         {
             if (Ref.Equal(this.name, this.asterisk) || Ref.Equal(curNode.Name, this.name))
             {
                 return(true);
             }
         }
         else if ((Ref.Equal(this.localName, this.asterisk) || Ref.Equal(curNode.LocalName, this.localName)) && (Ref.Equal(this.namespaceURI, this.asterisk) || (curNode.NamespaceURI == this.namespaceURI)))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.AddNamespace"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public virtual void AddNamespace(string prefix, string uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (prefix == null)
            {
                throw new ArgumentNullException("prefix");
            }
            prefix = nameTable.Add(prefix);
            uri    = nameTable.Add(uri);

            if (Ref.Equal(xml, prefix) || Ref.Equal(xmlNs, prefix))
            {
                throw new ArgumentException(Res.GetString(Res.Xml_InvalidPrefix));
            }

            for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
            {
                NsDecl decl = (NsDecl)decls[declIndex];
                if (Ref.Equal(decl.Prefix, prefix))
                {
                    decl.Uri = uri;
                    return; // redefine
                }
            } /* else */
            {
                NsDecl decl = (NsDecl)decls.Push();
                if (decl == null)
                {
                    decl = new NsDecl();
                    decls.AddToTop(decl);
                }
                decl.Prefix = prefix;
                decl.Uri    = uri;
                count++;
                if (prefix == string.Empty)
                {
                    defaultNs = decl;
                }
            }
        }
Esempio n. 10
0
 private void RemoveNamespace(string prefix, string localName)
 {
     for (int i = 0; i < nsAttrCount; i++)
     {
         if (Ref.Equal(prefix, nsAttributes[i].prefix) &&
             Ref.Equal(localName, nsAttributes[i].localName))
         {
             if (i < nsAttrCount - 1)
             {
                 // swap
                 NodeData tmpNodeData = nsAttributes[i];
                 nsAttributes[i] = nsAttributes[nsAttrCount - 1];
                 nsAttributes[nsAttrCount - 1] = tmpNodeData;
             }
             nsAttrCount--;
             break;
         }
     }
 }
Esempio n. 11
0
        // Moves to the attribute with the specified LocalName and NamespaceURI
        public override bool MoveToAttribute(string name, string ns)
        {
            ns   = (ns == null) ? string.Empty : _coreReaderNameTable.Get(ns);
            name = _coreReaderNameTable.Get(name);
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < _attributeCount; i++)
            {
                attribute = _attributeEvents[i];
                if (Ref.Equal(attribute.LocalName, name) &&
                    Ref.Equal(attribute.Namespace, ns))
                {
                    _currentAttrIndex = i;
                    _cachedNode       = _attributeEvents[i];
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 12
0
        private int GetAttributeIndexWithoutPrefix(string name)
        {
            name = _coreReaderNameTable.Get(name);
            if (name == null)
            {
                return(-1);
            }
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < _attributeCount; i++)
            {
                attribute = _attributeEvents[i];
                if (Ref.Equal(attribute.LocalName, name) && attribute.Prefix.Length == 0)
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 13
0
        // Reads to the first descendant of the current element with the given Name.
        public virtual bool ReadToDescendant(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw new ArgumentException(name, "name");
            }

            // save the element or root depth
            int parentDepth = Depth;

            if (NodeType != XmlNodeType.Element)
            {
                // adjust the depth if we are on root node
                if (ReadState == ReadState.Initial)
                {
                    Debug.Assert(parentDepth == 0);
                    parentDepth--;
                }
                else
                {
                    return(false);
                }
            }
            else if (IsEmptyElement)
            {
                return(false);
            }

            // atomize name
            name = NameTable.Add(name);

            // find the descendant
            while (Read() && Depth > parentDepth)
            {
                if (NodeType == XmlNodeType.Element && Ref.Equal(name, Name))
                {
                    return(true);
                }
            }

            Debug.Assert(NodeType == XmlNodeType.EndElement || (parentDepth == -1 && ReadState == ReadState.EndOfFile));
            return(false);
        }
Esempio n. 14
0
        private int GetAttributeIndexWithPrefix(string name)
        {
            name = _coreReaderNameTable.Get(name);
            if (name == null)
            {
                return(-1);
            }
            ValidatingReaderNodeData attribute;

            for (int i = 0; i < _attributeCount; i++)
            {
                attribute = _attributeEvents[i];
                if (Ref.Equal(attribute.GetAtomizedNameWPrefix(_coreReaderNameTable), name))
                {
                    return(i);
                }
            }
            return(-1);
        }
Esempio n. 15
0
        public virtual bool ReadToNextSibling(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, nameof(name));
            }
            name = this.NameTable.Add(name);
            XmlNodeType nodeType;

            do
            {
                this.SkipSubtree();
                nodeType = this.NodeType;
                if (nodeType == XmlNodeType.Element && Ref.Equal(name, this.Name))
                {
                    return(true);
                }
            }while (nodeType != XmlNodeType.EndElement && !this.EOF);
            return(false);
        }
Esempio n. 16
0
        // Reads to the following element with the given Name.
        public virtual bool ReadToFollowing(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, "name");
            }

            // atomize name
            name = NameTable.Add(name);

            // find following element with that name
            while (Read())
            {
                if (NodeType == XmlNodeType.Element && Ref.Equal(name, Name))
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 17
0
 public virtual bool ReadToFollowing(string localName, string namespaceURI)
 {
     if (localName == null || localName.Length == 0)
     {
         throw XmlExceptionHelper.CreateInvalidNameArgumentException(localName, nameof(localName));
     }
     if (namespaceURI == null)
     {
         throw new ArgumentNullException(nameof(namespaceURI));
     }
     localName    = this.NameTable.Add(localName);
     namespaceURI = this.NameTable.Add(namespaceURI);
     while (this.Read())
     {
         if (this.NodeType == XmlNodeType.Element && Ref.Equal(localName, this.LocalName) && Ref.Equal(namespaceURI, this.NamespaceURI))
         {
             return(true);
         }
     }
     return(false);
 }
        private void ValidateSingleElement(XmlElement elementNode, bool skipToEnd, XmlSchemaInfo newSchemaInfo)
        {
            this.nsManager.PushScope();
            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attribute  = null;
            string xsiNil  = null;
            string xsiType = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attribute = attributes[i];
                string namespaceURI = attribute.NamespaceURI;
                string localName    = attribute.LocalName;
                if (Ref.Equal(namespaceURI, this.NsXsi))
                {
                    if (Ref.Equal(localName, this.XsiType))
                    {
                        xsiType = attribute.Value;
                    }
                    else if (Ref.Equal(localName, this.XsiNil))
                    {
                        xsiNil = attribute.Value;
                    }
                }
                else if (Ref.Equal(namespaceURI, this.NsXmlNs))
                {
                    this.nsManager.AddNamespace((attribute.Prefix.Length == 0) ? string.Empty : attribute.LocalName, attribute.Value);
                }
            }
            this.validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, newSchemaInfo, xsiType, xsiNil, null, null);
            if (skipToEnd)
            {
                this.validator.ValidateEndOfAttributes(newSchemaInfo);
                this.validator.SkipToEndElement(newSchemaInfo);
                this.nsManager.PopScope();
            }
        }
 /// <include file='doc\XmlNamespaceManager.uex' path='docs/doc[@for="XmlNamespaceManager.RemoveNamespace"]/*' />
 /// <devdoc>
 ///    <para>[To be supplied.]</para>
 /// </devdoc>
 public virtual void RemoveNamespace(string prefix, string uri)
 {
     if (uri == null)
     {
         throw new ArgumentNullException("uri");
     }
     if (prefix == null)
     {
         throw new ArgumentNullException("prefix");
     }
     prefix = nameTable.Get(prefix);
     uri    = nameTable.Get(uri);
     if (prefix != null && uri != null)
     {
         for (int declIndex = decls.Length - 1; declIndex >= decls.Length - count; declIndex--)
         {
             NsDecl decl = (NsDecl)decls[declIndex];
             if (Ref.Equal(decl.Prefix, prefix) && Ref.Equal(decl.Uri, uri))
             {
                 decl.Uri = null;
             }
         }
     }
 }
Esempio n. 20
0
 // if the current node a matching element node
 private bool IsMatch(XmlNode curNode)
 {
     if (curNode.NodeType == XmlNodeType.Element)
     {
         if (_name != null)
         {
             if (Ref.Equal(_name, _asterisk) || Ref.Equal(curNode.Name, _name))
             {
                 return(true);
             }
         }
         else
         {
             if (
                 (Ref.Equal(_localName, _asterisk) || Ref.Equal(curNode.LocalName, _localName)) &&
                 (Ref.Equal(_namespaceURI, _asterisk) || curNode.NamespaceURI == _namespaceURI)
                 )
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Esempio n. 21
0
        // Reads to the next sibling of the current element with the given Name.
        public virtual bool ReadToNextSibling(string name)
        {
            if (name == null || name.Length == 0)
            {
                throw XmlExceptionHelper.CreateInvalidNameArgumentException(name, "name");
            }

            // atomize name
            name = NameTable.Add(name);

            // find the next sibling
            XmlNodeType nt;

            do
            {
                SkipSubtree();
                nt = NodeType;
                if (nt == XmlNodeType.Element && Ref.Equal(name, Name))
                {
                    return(true);
                }
            } while (nt != XmlNodeType.EndElement && !EOF);
            return(false);
        }
Esempio n. 22
0
        public virtual void AddNamespace(string prefix, string uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }

            if (prefix == null)
            {
                throw new ArgumentNullException(nameof(prefix));
            }

            prefix = _nameTable.Add(prefix);
            uri    = _nameTable.Add(uri);

            if ((Ref.Equal(_xml, prefix) && !uri.Equals(XmlReservedNs.NsXml)))
            {
                throw new ArgumentException(SR.Xml_XmlPrefix);
            }
            if (Ref.Equal(_xmlNs, prefix))
            {
                throw new ArgumentException(SR.Xml_XmlnsPrefix);
            }

            int declIndex         = LookupNamespaceDecl(prefix);
            int previousDeclIndex = -1;

            if (declIndex != -1)
            {
                if (_nsdecls[declIndex].scopeId == _scopeId)
                {
                    // redefine if in the same scope
                    _nsdecls[declIndex].uri = uri;
                    return;
                }
                else
                {
                    // othewise link
                    previousDeclIndex = declIndex;
                }
            }

            // set new namespace declaration
            if (_lastDecl == _nsdecls.Length - 1)
            {
                NamespaceDeclaration[] newNsdecls = new NamespaceDeclaration[_nsdecls.Length * 2];
                Array.Copy(_nsdecls, 0, newNsdecls, 0, _nsdecls.Length);
                _nsdecls = newNsdecls;
            }

            _nsdecls[++_lastDecl].Set(prefix, uri, _scopeId, previousDeclIndex);

            // add to hashTable
            if (_useHashtable)
            {
                _hashTable[prefix] = _lastDecl;
            }
            // or create a new hashTable if the threashold has been reached
            else if (_lastDecl >= MinDeclsCountForHashtable)
            {
                // add all to hash table
                Debug.Assert(_hashTable == null);
                _hashTable = new Dictionary <string, int>(_lastDecl);
                for (int i = 0; i <= _lastDecl; i++)
                {
                    _hashTable[_nsdecls[i].prefix] = i;
                }
                _useHashtable = true;
            }
        }
Esempio n. 23
0
        private async Task ProcessElementEventAsync()
        {
            if (_processInlineSchema && IsXSDRoot(_coreReader.LocalName, _coreReader.NamespaceURI) && _coreReader.Depth > 0)
            {
                _xmlSchemaInfo.Clear();
                _attributeCount = _coreReaderAttributeCount = _coreReader.AttributeCount;
                if (!_coreReader.IsEmptyElement)
                {
                    // If its not empty schema, then parse else ignore
                    _inlineSchemaParser = new Parser(SchemaType.XSD, _coreReaderNameTable, _validator.SchemaSet.GetSchemaNames(_coreReaderNameTable), _validationEvent);
                    await _inlineSchemaParser.StartParsingAsync(_coreReader, null).ConfigureAwait(false);

                    _inlineSchemaParser.ParseReaderNode();
                    _validationState = ValidatingReaderState.ParseInlineSchema;
                }
                else
                {
                    _validationState = ValidatingReaderState.ClearAttributes;
                }
            }
            else
            {
                // Validate element
                // Clear previous data
                _atomicValue = null;
                _originalAtomicValueString = null;
                _xmlSchemaInfo.Clear();

                if (_manageNamespaces)
                {
                    Debug.Assert(_nsManager != null);
                    _nsManager.PushScope();
                }

                // Find Xsi attributes that need to be processed before validating the element
                string?xsiSchemaLocation = null;
                string?xsiNoNamespaceSL  = null;
                string?xsiNil            = null;
                string?xsiType           = null;

                if (_coreReader.MoveToFirstAttribute())
                {
                    do
                    {
                        string objectNs   = _coreReader.NamespaceURI;
                        string objectName = _coreReader.LocalName;
                        if (Ref.Equal(objectNs, _nsXsi))
                        {
                            if (Ref.Equal(objectName, _xsiSchemaLocation))
                            {
                                xsiSchemaLocation = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiNoNamespaceSchemaLocation))
                            {
                                xsiNoNamespaceSL = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiType))
                            {
                                xsiType = _coreReader.Value;
                            }
                            else if (Ref.Equal(objectName, _xsiNil))
                            {
                                xsiNil = _coreReader.Value;
                            }
                        }

                        if (_manageNamespaces && Ref.Equal(_coreReader.NamespaceURI, _nsXmlNs))
                        {
                            Debug.Assert(_nsManager != null);
                            _nsManager.AddNamespace(_coreReader.Prefix.Length == 0 ? string.Empty : _coreReader.LocalName, _coreReader.Value);
                        }
                    } while (_coreReader.MoveToNextAttribute());
                    _coreReader.MoveToElement();
                }

                _validator.ValidateElement(_coreReader.LocalName, _coreReader.NamespaceURI, _xmlSchemaInfo, xsiType, xsiNil, xsiSchemaLocation, xsiNoNamespaceSL);
                ValidateAttributes();
                _validator.ValidateEndOfAttributes(_xmlSchemaInfo);
                if (_coreReader.IsEmptyElement)
                {
                    await ProcessEndElementEventAsync().ConfigureAwait(false);
                }

                _validationState = ValidatingReaderState.ClearAttributes;
            }
        }
Esempio n. 24
0
        internal string GetPrefixOfNamespaceStrict(string namespaceURI)
        {
            XmlDocument doc = Document;

            if (doc != null)
            {
                namespaceURI = doc.NameTable.Add(namespaceURI);

                XmlNode node = this;
                while (node != null)
                {
                    if (node.NodeType == XmlNodeType.Element)
                    {
                        XmlElement elem = (XmlElement)node;
                        if (elem.HasAttributes)
                        {
                            XmlAttributeCollection attrs = elem.Attributes;
                            for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
                            {
                                XmlAttribute attr = attrs[iAttr];
                                if (attr.Prefix.Length == 0)
                                {
                                    if (Ref.Equal(attr.LocalName, doc.strXmlns))
                                    {
                                        if (attr.Value == namespaceURI)
                                        {
                                            return(string.Empty); // found xmlns="namespaceURI"
                                        }
                                    }
                                }
                                else if (Ref.Equal(attr.Prefix, doc.strXmlns))
                                {
                                    if (attr.Value == namespaceURI)
                                    {
                                        return(attr.LocalName); // found xmlns:prefix="namespaceURI"
                                    }
                                }
                                else if (Ref.Equal(attr.NamespaceURI, namespaceURI))
                                {
                                    return(attr.Prefix); // found prefix:attr
                                                         // with prefix bound to namespaceURI
                                }
                            }
                        }
                        if (Ref.Equal(node.NamespaceURI, namespaceURI))
                        {
                            return(node.Prefix);
                        }
                        node = node.ParentNode;
                    }
                    else if (node.NodeType == XmlNodeType.Attribute)
                    {
                        node = ((XmlAttribute)node).OwnerElement;
                    }
                    else
                    {
                        node = node.ParentNode;
                    }
                }
                if (Ref.Equal(doc.strReservedXml, namespaceURI))
                { // xmlns:xml
                    return(doc.strXml);
                }
                else if (Ref.Equal(doc.strReservedXmlns, namespaceURI))
                { // xmlns:xmlns
                    return(doc.strXmlns);
                }
            }
            return(null);
        }
Esempio n. 25
0
        internal string GetNamespaceOfPrefixStrict(string prefix)
        {
            XmlDocument doc = Document;

            if (doc != null)
            {
                prefix = doc.NameTable.Get(prefix);
                if (prefix == null)
                {
                    return(null);
                }

                XmlNode node = this;
                while (node != null)
                {
                    if (node.NodeType == XmlNodeType.Element)
                    {
                        XmlElement elem = (XmlElement)node;
                        if (elem.HasAttributes)
                        {
                            XmlAttributeCollection attrs = elem.Attributes;
                            if (prefix.Length == 0)
                            {
                                for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
                                {
                                    XmlAttribute attr = attrs[iAttr];
                                    if (attr.Prefix.Length == 0)
                                    {
                                        if (Ref.Equal(attr.LocalName, doc.strXmlns))
                                        {
                                            return(attr.Value); // found xmlns
                                        }
                                    }
                                }
                            }
                            else
                            {
                                for (int iAttr = 0; iAttr < attrs.Count; iAttr++)
                                {
                                    XmlAttribute attr = attrs[iAttr];
                                    if (Ref.Equal(attr.Prefix, doc.strXmlns))
                                    {
                                        if (Ref.Equal(attr.LocalName, prefix))
                                        {
                                            return(attr.Value); // found xmlns:prefix
                                        }
                                    }
                                    else if (Ref.Equal(attr.Prefix, prefix))
                                    {
                                        return(attr.NamespaceURI); // found prefix:attr
                                    }
                                }
                            }
                        }
                        if (Ref.Equal(node.Prefix, prefix))
                        {
                            return(node.NamespaceURI);
                        }
                        node = node.ParentNode;
                    }
                    else if (node.NodeType == XmlNodeType.Attribute)
                    {
                        node = ((XmlAttribute)node).OwnerElement;
                    }
                    else
                    {
                        node = node.ParentNode;
                    }
                }
                if (Ref.Equal(doc.strXml, prefix))
                { // xmlns:xml
                    return(doc.strReservedXml);
                }
                else if (Ref.Equal(doc.strXmlns, prefix))
                { // xmlns:xmlns
                    return(doc.strReservedXmlns);
                }
            }
            return(null);
        }
        public IDictionary <string, string> GetNamespacesInScope(XmlNamespaceScope scope)
        {
            IDictionary <string, string> namespacesInScope = this.nsManager.GetNamespacesInScope(scope);

            if (scope != XmlNamespaceScope.Local)
            {
                XmlNode startNode = this.startNode;
                while (startNode != null)
                {
                    XmlAttributeCollection attributes;
                    int          num;
                    XmlAttribute attribute;
                    switch (startNode.NodeType)
                    {
                    case XmlNodeType.Element:
                    {
                        XmlElement element = (XmlElement)startNode;
                        if (!element.HasAttributes)
                        {
                            goto Label_00E4;
                        }
                        attributes = element.Attributes;
                        num        = 0;
                        goto Label_00D7;
                    }

                    case XmlNodeType.Attribute:
                    {
                        startNode = ((XmlAttribute)startNode).OwnerElement;
                        continue;
                    }

                    default:
                        goto Label_00FB;
                    }
Label_005C:
                    attribute = attributes[num];
                    if (Ref.Equal(attribute.NamespaceURI, this.document.strReservedXmlns))
                    {
                        if (attribute.Prefix.Length == 0)
                        {
                            if (!namespacesInScope.ContainsKey(string.Empty))
                            {
                                namespacesInScope.Add(string.Empty, attribute.Value);
                            }
                        }
                        else if (!namespacesInScope.ContainsKey(attribute.LocalName))
                        {
                            namespacesInScope.Add(attribute.LocalName, attribute.Value);
                        }
                    }
                    num++;
Label_00D7:
                    if (num < attributes.Count)
                    {
                        goto Label_005C;
                    }
Label_00E4:
                    startNode = startNode.ParentNode;
                    continue;
Label_00FB:
                    startNode = startNode.ParentNode;
                }
            }
            return(namespacesInScope);
        }
        internal string GetPrefixOfNamespaceStrict(string namespaceURI)
        {
            XmlDocument document = this.Document;

            if (document != null)
            {
                namespaceURI = document.NameTable.Add(namespaceURI);
                XmlNode parentNode = this;
                while (parentNode != null)
                {
                    if (parentNode.NodeType == XmlNodeType.Element)
                    {
                        XmlElement element = (XmlElement)parentNode;
                        if (element.HasAttributes)
                        {
                            XmlAttributeCollection attributes = element.Attributes;
                            for (int i = 0; i < attributes.Count; i++)
                            {
                                XmlAttribute attribute = attributes[i];
                                if (attribute.Prefix.Length == 0)
                                {
                                    if (Ref.Equal(attribute.LocalName, document.strXmlns) && (attribute.Value == namespaceURI))
                                    {
                                        return(string.Empty);
                                    }
                                }
                                else if (Ref.Equal(attribute.Prefix, document.strXmlns))
                                {
                                    if (attribute.Value == namespaceURI)
                                    {
                                        return(attribute.LocalName);
                                    }
                                }
                                else if (Ref.Equal(attribute.NamespaceURI, namespaceURI))
                                {
                                    return(attribute.Prefix);
                                }
                            }
                        }
                        if (Ref.Equal(parentNode.NamespaceURI, namespaceURI))
                        {
                            return(parentNode.Prefix);
                        }
                        parentNode = parentNode.ParentNode;
                    }
                    else if (parentNode.NodeType == XmlNodeType.Attribute)
                    {
                        parentNode = ((XmlAttribute)parentNode).OwnerElement;
                    }
                    else
                    {
                        parentNode = parentNode.ParentNode;
                    }
                }
                if (Ref.Equal(document.strReservedXml, namespaceURI))
                {
                    return(document.strXml);
                }
                if (Ref.Equal(document.strReservedXmlns, namespaceURI))
                {
                    return(document.strXmlns);
                }
            }
            return(null);
        }
        internal string GetNamespaceOfPrefixStrict(string prefix)
        {
            XmlDocument document = this.Document;

            if (document != null)
            {
                prefix = document.NameTable.Get(prefix);
                if (prefix == null)
                {
                    return(null);
                }
                XmlNode parentNode = this;
                while (parentNode != null)
                {
                    if (parentNode.NodeType == XmlNodeType.Element)
                    {
                        XmlElement element = (XmlElement)parentNode;
                        if (element.HasAttributes)
                        {
                            XmlAttributeCollection attributes = element.Attributes;
                            if (prefix.Length == 0)
                            {
                                for (int i = 0; i < attributes.Count; i++)
                                {
                                    XmlAttribute attribute = attributes[i];
                                    if ((attribute.Prefix.Length == 0) && Ref.Equal(attribute.LocalName, document.strXmlns))
                                    {
                                        return(attribute.Value);
                                    }
                                }
                            }
                            else
                            {
                                for (int j = 0; j < attributes.Count; j++)
                                {
                                    XmlAttribute attribute2 = attributes[j];
                                    if (Ref.Equal(attribute2.Prefix, document.strXmlns))
                                    {
                                        if (Ref.Equal(attribute2.LocalName, prefix))
                                        {
                                            return(attribute2.Value);
                                        }
                                    }
                                    else if (Ref.Equal(attribute2.Prefix, prefix))
                                    {
                                        return(attribute2.NamespaceURI);
                                    }
                                }
                            }
                        }
                        if (Ref.Equal(parentNode.Prefix, prefix))
                        {
                            return(parentNode.NamespaceURI);
                        }
                        parentNode = parentNode.ParentNode;
                    }
                    else if (parentNode.NodeType == XmlNodeType.Attribute)
                    {
                        parentNode = ((XmlAttribute)parentNode).OwnerElement;
                    }
                    else
                    {
                        parentNode = parentNode.ParentNode;
                    }
                }
                if (Ref.Equal(document.strXml, prefix))
                {
                    return(document.strReservedXml);
                }
                if (Ref.Equal(document.strXmlns, prefix))
                {
                    return(document.strReservedXmlns);
                }
            }
            return(null);
        }
 protected override bool Match(XmlNode node)
 {
     return(Ref.Equal(node.LocalName, this.localNameAtom) && Ref.Equal(node.NamespaceURI, this.nsAtom));
 }
Esempio n. 30
0
        private void ValidateElement()
        {
            _nsManager.PushScope();
            XmlElement elementNode = _currentNode as XmlElement;

            Debug.Assert(elementNode != null);

            XmlAttributeCollection attributes = elementNode.Attributes;
            XmlAttribute           attr       = null;

            //Find Xsi attributes that need to be processed before validating the element
            string xsiNil  = null;
            string xsiType = null;

            for (int i = 0; i < attributes.Count; i++)
            {
                attr = attributes[i];
                string objectNs   = attr.NamespaceURI;
                string objectName = attr.LocalName;
                Debug.Assert(_nameTable.Get(attr.NamespaceURI) != null);
                Debug.Assert(_nameTable.Get(attr.LocalName) != null);

                if (Ref.Equal(objectNs, _nsXsi))
                {
                    if (Ref.Equal(objectName, _xsiType))
                    {
                        xsiType = attr.Value;
                    }
                    else if (Ref.Equal(objectName, _xsiNil))
                    {
                        xsiNil = attr.Value;
                    }
                }
                else if (Ref.Equal(objectNs, _nsXmlNs))
                {
                    _nsManager.AddNamespace(attr.Prefix.Length == 0 ? string.Empty : attr.LocalName, attr.Value);
                }
            }
            _validator.ValidateElement(elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo, xsiType, xsiNil, null, null);
            ValidateAttributes(elementNode);
            _validator.ValidateEndOfAttributes(_schemaInfo);

            //If element has children, drill down
            for (XmlNode child = elementNode.FirstChild; child != null; child = child.NextSibling)
            {
                ValidateNode(child);
            }
            //Validate end of element
            _currentNode = elementNode; //Reset current Node for validation call back
            _validator.ValidateEndElement(_schemaInfo);
            //Get XmlName, as memberType / validity might be set now
            if (_psviAugmentation)
            {
                elementNode.XmlName = _document.AddXmlName(elementNode.Prefix, elementNode.LocalName, elementNode.NamespaceURI, _schemaInfo);
                if (_schemaInfo.IsDefault)
                { //the element has a default value
                    XmlText textNode = _document.CreateTextNode(_schemaInfo.SchemaElement.ElementDecl.DefaultValueRaw);
                    elementNode.AppendChild(textNode);
                }
            }

            _nsManager.PopScope(); //Pop current namespace scope
        }