private void GetNamespaceToRender( [NotNull] string nsPrefix, [NotNull] SortedList attrListToRender, [NotNull] SortedList nsListToRender, [NotNull] Hashtable nsLocallyDeclared) { foreach (XmlAttribute key in nsListToRender.GetKeyList()) { if (Exml.HasNamespacePrefix(key, nsPrefix)) { return; } } foreach (XmlNode key in attrListToRender.GetKeyList()) { if (key.LocalName.Equals(nsPrefix)) { return; } } XmlAttribute a = (XmlAttribute)nsLocallyDeclared[nsPrefix]; int depth1; XmlAttribute withMatchingPrefix1 = GetNearestRenderedNamespaceWithMatchingPrefix(nsPrefix, out depth1); if (a != null) { if (!Exml.IsNonRedundantNamespaceDecl(a, withMatchingPrefix1)) { return; } nsLocallyDeclared.Remove(nsPrefix); if (Exml.IsXmlNamespaceNode(a)) { attrListToRender.Add(a, null); } else { nsListToRender.Add(a, null); } } else { int depth2; var withMatchingPrefix2 = GetNearestUnrenderedNamespaceWithMatchingPrefix(nsPrefix, out depth2); if (withMatchingPrefix2 == null || depth2 <= depth1 || !Exml.IsNonRedundantNamespaceDecl(withMatchingPrefix2, withMatchingPrefix1)) { return; } if (Exml.IsXmlNamespaceNode(withMatchingPrefix2)) { attrListToRender.Add(withMatchingPrefix2, null); } else { nsListToRender.Add(withMatchingPrefix2, null); } } }
internal override void GetNamespacesToRender( [NotNull] XmlElement element, [NotNull] SortedList attrListToRender, [NotNull] SortedList nsListToRender, [NotNull] Hashtable nsLocallyDeclared) { object[] objArray = new object[nsLocallyDeclared.Count]; nsLocallyDeclared.Values.CopyTo(objArray, 0); foreach (XmlAttribute a in objArray) { var namespacePrefix = Exml.GetNamespacePrefix(a); if (namespacePrefix == null) { continue; } var withMatchingPrefix = GetNearestRenderedNamespaceWithMatchingPrefix(namespacePrefix, out _); if (!Exml.IsNonRedundantNamespaceDecl(a, withMatchingPrefix)) { continue; } nsLocallyDeclared.Remove(namespacePrefix); if (Exml.IsXmlNamespaceNode(a)) { attrListToRender.Add(a, null); } else { nsListToRender.Add(a, null); } } for (int i = m_ancestorStack.Count - 1; i >= 0; --i) { var values = GetScopeAt(i)?.GetUnrendered()?.Values; if (values != null) { foreach (XmlAttribute a in values) { if (a == null) { continue; } var prefix = Exml.GetNamespacePrefix(a); if (prefix == null) { continue; } GetNamespaceToRender(prefix, attrListToRender, nsListToRender, nsLocallyDeclared); } } } }
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); }