// Element Nodes // If the element is not in the node-set, then the result is obtained // by processing the namespace axis, then the attribute axis, then // processing the child nodes of the element that are in the node-set // (in document order). If the element is inthe node-set, then the result // is an open angle bracket (<), the element QName, the result of // processing the namespace axis, the result of processing the attribute // axis, a close angle bracket (>), the result of processing the child // nodes of the element that are in the node-set (in document order), an // open angle bracket, a forward slash (/), the element QName, and a close // angle bracket. private void WriteElementNode(XmlNode node, bool visible) { // Console.WriteLine ("Debug: element node"); // remember current state int savedPrevVisibleNamespacesStart = prevVisibleNamespacesStart; int savedPrevVisibleNamespacesEnd = prevVisibleNamespacesEnd; int savedVisibleNamespacesSize = visibleNamespaces.Count; XmlCanonicalizerState s = state; if (visible && state == XmlCanonicalizerState.BeforeDocElement) { state = XmlCanonicalizerState.InsideDocElement; } // write start tag if (visible) { res.Append("<"); res.Append(node.Name); } // this is odd but you can select namespaces // and attributes even if node itself is not visible WriteNamespacesAxis(node, visible); WriteAttributesAxis(node); if (visible) { res.Append(">"); } // write children for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) { WriteNode(child); } // write end tag if (visible) { res.Append("</"); res.Append(node.Name); res.Append(">"); } // restore state if (visible && s == XmlCanonicalizerState.BeforeDocElement) { state = XmlCanonicalizerState.AfterDocElement; } prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart; prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd; if (visibleNamespaces.Count > savedVisibleNamespacesSize) { visibleNamespaces.RemoveRange(savedVisibleNamespacesSize, visibleNamespaces.Count - savedVisibleNamespacesSize); } }
void Initialize() { state = XmlCanonicalizerState.BeforeDocElement; visibleNamespaces = new ArrayList(); prevVisibleNamespacesStart = 0; prevVisibleNamespacesEnd = 0; res.Length = 0; }
void Initialize () { state = XmlCanonicalizerState.BeforeDocElement; visibleNamespaces = new ArrayList (); prevVisibleNamespacesStart = 0; prevVisibleNamespacesEnd = 0; res.Length = 0; }
private void WriteDocumentNode(XmlNode node) { state = XmlCanonicalizerState.BeforeDocElement; for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) { WriteNode(child); } }
public XmlCanonicalizer (bool withComments, bool excC14N) { res = new StringBuilder (); comments = withComments; exclusive = excC14N; state = XmlCanonicalizerState.BeforeDocElement; visibleNamespaces = new ArrayList (); prevVisibleNamespacesStart = 0; prevVisibleNamespacesEnd = 0; }
public XmlCanonicalizer(bool withComments, bool excC14N) { res = new StringBuilder(); comments = withComments; exclusive = excC14N; state = XmlCanonicalizerState.BeforeDocElement; visibleNamespaces = new ArrayList(); prevVisibleNamespacesStart = 0; prevVisibleNamespacesEnd = 0; }
//interface mod public Stream Canonicalize(XmlNode node) { //WriteDocumentNode (doc); state = XmlCanonicalizerState.BeforeDocElement; //for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) // WriteNode (child); WriteNode(node); UTF8Encoding utf8 = new UTF8Encoding(); byte[] data = utf8.GetBytes(res.ToString()); return(new MemoryStream(data)); }
// Element Nodes // If the element is not in the node-set, then the result is obtained // by processing the namespace axis, then the attribute axis, then // processing the child nodes of the element that are in the node-set // (in document order). If the element is inthe node-set, then the result // is an open angle bracket (<), the element QName, the result of // processing the namespace axis, the result of processing the attribute // axis, a close angle bracket (>), the result of processing the child // nodes of the element that are in the node-set (in document order), an // open angle bracket, a forward slash (/), the element QName, and a close // angle bracket. private void WriteElementNode (XmlNode node, bool visible) { // Console.WriteLine ("Debug: element node"); // remember current state int savedPrevVisibleNamespacesStart = prevVisibleNamespacesStart; int savedPrevVisibleNamespacesEnd = prevVisibleNamespacesEnd; int savedVisibleNamespacesSize = visibleNamespaces.Count; XmlCanonicalizerState s = state; if (visible && state == XmlCanonicalizerState.BeforeDocElement) state = XmlCanonicalizerState.InsideDocElement; // write start tag if (visible) { res.Append ("<"); res.Append (node.Name); } // this is odd but you can select namespaces // and attributes even if node itself is not visible WriteNamespacesAxis (node, visible); WriteAttributesAxis (node); if (visible) res.Append (">"); // write children for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) WriteNode (child); // write end tag if (visible) { res.Append ("</"); res.Append (node.Name); res.Append (">"); } // restore state if (visible && s == XmlCanonicalizerState.BeforeDocElement) state = XmlCanonicalizerState.AfterDocElement; prevVisibleNamespacesStart = savedPrevVisibleNamespacesStart; prevVisibleNamespacesEnd = savedPrevVisibleNamespacesEnd; if (visibleNamespaces.Count > savedVisibleNamespacesSize) { visibleNamespaces.RemoveRange (savedVisibleNamespacesSize, visibleNamespaces.Count - savedVisibleNamespacesSize); } }
private void WriteDocumentNode (XmlNode node) { state = XmlCanonicalizerState.BeforeDocElement; for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling) WriteNode (child); }