Пример #1
0
        private void CheckAttributes(XmlAttributeNode[] attributeNodes, int attributeCount)
        {
            // For large numbers of attributes, sorting the attributes (n * lg(n)) is faster
            if (_attributeSorter == null)
                _attributeSorter = new AttributeSorter();

            if (!_attributeSorter.Sort(attributeNodes, attributeCount))
            {
                int attribute1, attribute2;
                _attributeSorter.GetIndeces(out attribute1, out attribute2);
                if (attributeNodes[attribute1].QNameType == QNameType.Xmlns)
                    XmlExceptionHelper.ThrowDuplicateXmlnsAttribute(this, attributeNodes[attribute1].Namespace.Prefix.GetString(), xmlnsNamespace);
                else
                    XmlExceptionHelper.ThrowDuplicateAttribute(this, attributeNodes[attribute1].Prefix.GetString(), attributeNodes[attribute2].Prefix.GetString(), attributeNodes[attribute1].LocalName.GetString(), attributeNodes[attribute1].Namespace.Uri.GetString());
            }
        }
Пример #2
0
        private void ProcessAttributes(XmlAttributeNode[] attributeNodes, int attributeCount)
        {
            for (int i = 0; i < attributeCount; i++)
            {
                XmlAttributeNode attributeNode = attributeNodes[i];
                if (attributeNode.QNameType == QNameType.Normal)
                {
                    PrefixHandle prefix = attributeNode.Prefix;
                    if (!prefix.IsEmpty)
                    {
                        attributeNode.Namespace = LookupNamespace(prefix);
                    }
                    else
                    {
                        attributeNode.Namespace = NamespaceManager.EmptyNamespace;
                    }
                    attributeNode.AttributeText.Namespace = attributeNode.Namespace;
                }
            }

            if (attributeCount > 1)
            {
                if (attributeCount < 12)
                {
                    // For small numbers of attributes, a naive n * (n - 1) / 2 comparisons to check for uniqueness is faster
                    for (int i = 0; i < attributeCount - 1; i++)
                    {
                        XmlAttributeNode attributeNode1 = attributeNodes[i];
                        QNameType qnameType = attributeNode1.QNameType;
                        if (qnameType == QNameType.Normal)
                        {
                            for (int j = i + 1; j < attributeCount; j++)
                            {
                                XmlAttributeNode attributeNode2 = attributeNodes[j];
                                if (attributeNode2.QNameType == QNameType.Normal && attributeNode1.LocalName == attributeNode2.LocalName && attributeNode1.Namespace.Uri == attributeNode2.Namespace.Uri)
                                {
                                    XmlExceptionHelper.ThrowDuplicateAttribute(this, attributeNode1.Prefix.GetString(), attributeNode2.Prefix.GetString(), attributeNode1.LocalName.GetString(), attributeNode1.Namespace.Uri.GetString());
                                }
                            }
                        }
                        else
                        {
                            DiagnosticUtility.DebugAssert(qnameType == QNameType.Xmlns, "");
                            for (int j = i + 1; j < attributeCount; j++)
                            {
                                XmlAttributeNode attributeNode2 = attributeNodes[j];
                                if (attributeNode2.QNameType == QNameType.Xmlns && attributeNode1.Namespace.Prefix == attributeNode2.Namespace.Prefix)
                                    XmlExceptionHelper.ThrowDuplicateAttribute(this, xmlns, xmlns, attributeNode1.Namespace.Prefix.GetString(), xmlnsNamespace);
                            }
                        }
                    }
                }
                else
                {
                    CheckAttributes(attributeNodes, attributeCount);
                }
            }
        }
Пример #3
0
 protected void FixXmlAttribute(XmlAttributeNode attributeNode)
 {
     if (attributeNode.Prefix == xml)
     {
         if (attributeNode.LocalName == "lang")
         {
             _nsMgr.AddLangAttribute(attributeNode.Value.GetString());
         }
         else if (attributeNode.LocalName == "space")
         {
             string value = attributeNode.Value.GetString();
             if (value == "preserve")
             {
                 _nsMgr.AddSpaceAttribute(XmlSpace.Preserve);
             }
             else if (value == "default")
             {
                 _nsMgr.AddSpaceAttribute(XmlSpace.Default);
             }
         }
     }
 }
Пример #4
0
 private XmlAttributeNode AddAttribute(QNameType qnameType, bool isAtomicValue)
 {
     int attributeIndex = _attributeCount;
     if (_attributeNodes == null)
     {
         _attributeNodes = new XmlAttributeNode[4];
     }
     else if (_attributeNodes.Length == attributeIndex)
     {
         XmlAttributeNode[] newAttributeNodes = new XmlAttributeNode[attributeIndex * 2];
         Array.Copy(_attributeNodes, 0, newAttributeNodes, 0, attributeIndex);
         _attributeNodes = newAttributeNodes;
     }
     XmlAttributeNode attributeNode = _attributeNodes[attributeIndex];
     if (attributeNode == null)
     {
         attributeNode = new XmlAttributeNode(_bufferReader);
         _attributeNodes[attributeIndex] = attributeNode;
     }
     attributeNode.QNameType = qnameType;
     attributeNode.IsAtomicValue = isAtomicValue;
     attributeNode.AttributeText.QNameType = qnameType;
     attributeNode.AttributeText.IsAtomicValue = isAtomicValue;
     _attributeCount++;
     return attributeNode;
 }
Пример #5
0
 public bool Sort(XmlAttributeNode[] attributeNodes, int attributeCount)
 {
     _attributeIndex1 = -1;
     _attributeIndex2 = -1;
     _attributeNodes = attributeNodes;
     _attributeCount = attributeCount;
     bool sorted = Sort();
     _attributeNodes = null;
     _attributeCount = 0;
     return sorted;
 }
Пример #6
0
 void SignAttribute(XmlSigningNodeWriter writer, XmlAttributeNode attributeNode)
 {
     QNameType qnameType = attributeNode.QNameType;
     if (qnameType == QNameType.Normal)
     {
         int prefixOffset, prefixLength;
         byte[] prefixBuffer = attributeNode.Prefix.GetString(out prefixOffset, out prefixLength);
         int localNameOffset, localNameLength;
         byte[] localNameBuffer = attributeNode.LocalName.GetString(out localNameOffset, out localNameLength);
         writer.WriteStartAttribute(prefixBuffer, prefixOffset, prefixLength, localNameBuffer, localNameOffset, localNameLength);
         attributeNode.Value.Sign(writer);
         writer.WriteEndAttribute();
     }
     else
     {
         Fx.Assert(qnameType == QNameType.Xmlns, "");
         int prefixOffset, prefixLength;
         byte[] prefixBuffer = attributeNode.Namespace.Prefix.GetString(out prefixOffset, out prefixLength);
         int nsOffset, nsLength;
         byte[] nsBuffer = attributeNode.Namespace.Uri.GetString(out nsOffset, out nsLength);
         writer.WriteXmlnsAttribute(prefixBuffer, prefixOffset, prefixLength, nsBuffer, nsOffset, nsLength);
     }
 }