コード例 #1
0
ファイル: CanonicalXmlDocument.cs プロジェクト: i-e-b/ADSD
 public void WriteHash(
     HashAlgorithm hash,
     DocPosition docPos,
     AncestralNamespaceContextManager anc)
 {
     docPos = DocPosition.BeforeRootElement;
     foreach (XmlNode childNode in this.ChildNodes)
     {
         if (childNode.NodeType == XmlNodeType.Element)
         {
             CanonicalizationDispatcher.WriteHash(childNode, hash, DocPosition.InRootElement, anc);
             docPos = DocPosition.AfterRootElement;
         }
         else
         {
             CanonicalizationDispatcher.WriteHash(childNode, hash, docPos, anc);
         }
     }
 }
コード例 #2
0
ファイル: CanonicalXmlElement.cs プロジェクト: i-e-b/ADSD
        public void WriteHash(
            HashAlgorithm hash,
            DocPosition docPos,
            AncestralNamespaceContextManager anc)
        {
            Hashtable              nsLocallyDeclared = new Hashtable();
            SortedList             sortedList        = new SortedList((IComparer) new NamespaceSortOrder());
            SortedList             attrListToRender  = new SortedList((IComparer) new AttributeSortOrder());
            UTF8Encoding           utF8Encoding      = new UTF8Encoding(false);
            XmlAttributeCollection attributes        = this.Attributes;

            if (attributes != null)
            {
                foreach (XmlAttribute attr in (XmlNamedNodeMap)attributes)
                {
                    if (((CanonicalXmlAttribute)attr).IsInNodeSet || Exml.IsNamespaceNode((XmlNode)attr) || Exml.IsXmlNamespaceNode((XmlNode)attr))
                    {
                        if (Exml.IsNamespaceNode((XmlNode)attr))
                        {
                            anc.TrackNamespaceNode(attr, sortedList, nsLocallyDeclared);
                        }
                        else if (Exml.IsXmlNamespaceNode((XmlNode)attr))
                        {
                            anc.TrackXmlNamespaceNode(attr, sortedList, attrListToRender, nsLocallyDeclared);
                        }
                        else if (this.IsInNodeSet)
                        {
                            attrListToRender.Add((object)attr, (object)null);
                        }
                    }
                }
            }
            if (!CanonicalXmlNodeList.IsCommittedNamespace((XmlElement)this, this.Prefix, this.NamespaceURI))
            {
                XmlAttribute attribute = this.OwnerDocument.CreateAttribute(this.Prefix.Length > 0 ? "xmlns:" + this.Prefix : "xmlns");
                attribute.Value = this.NamespaceURI;
                anc.TrackNamespaceNode(attribute, sortedList, nsLocallyDeclared);
            }
            if (this.IsInNodeSet)
            {
                anc.GetNamespacesToRender((XmlElement)this, attrListToRender, sortedList, nsLocallyDeclared);
                byte[] bytes1 = utF8Encoding.GetBytes("<" + this.Name);
                hash.TransformBlock(bytes1, 0, bytes1.Length, bytes1, 0);
                foreach (object key in (IEnumerable)sortedList.GetKeyList())
                {
                    (key as CanonicalXmlAttribute).WriteHash(hash, docPos, anc);
                }
                foreach (object key in (IEnumerable)attrListToRender.GetKeyList())
                {
                    (key as CanonicalXmlAttribute).WriteHash(hash, docPos, anc);
                }
                byte[] bytes2 = utF8Encoding.GetBytes(">");
                hash.TransformBlock(bytes2, 0, bytes2.Length, bytes2, 0);
            }
            anc.EnterElementContext();
            anc.LoadUnrenderedNamespaces(nsLocallyDeclared);
            anc.LoadRenderedNamespaces(sortedList);
            foreach (XmlNode childNode in this.ChildNodes)
            {
                CanonicalizationDispatcher.WriteHash(childNode, hash, docPos, anc);
            }
            anc.ExitElementContext();
            if (!this.IsInNodeSet)
            {
                return;
            }
            byte[] bytes = utF8Encoding.GetBytes("</" + this.Name + ">");
            hash.TransformBlock(bytes, 0, bytes.Length, bytes, 0);
        }