コード例 #1
0
        // 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);
            }
        }
コード例 #2
0
 void Initialize()
 {
     state                      = XmlCanonicalizerState.BeforeDocElement;
     visibleNamespaces          = new ArrayList();
     prevVisibleNamespacesStart = 0;
     prevVisibleNamespacesEnd   = 0;
     res.Length                 = 0;
 }
コード例 #3
0
		void Initialize ()
		{
			state = XmlCanonicalizerState.BeforeDocElement;
			visibleNamespaces = new ArrayList ();
			prevVisibleNamespacesStart = 0;
			prevVisibleNamespacesEnd = 0;
			res.Length = 0;
		}
コード例 #4
0
 private void WriteDocumentNode(XmlNode node)
 {
     state = XmlCanonicalizerState.BeforeDocElement;
     for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
     {
         WriteNode(child);
     }
 }
コード例 #5
0
		public XmlCanonicalizer (bool withComments, bool excC14N)
		{	    
			res = new StringBuilder ();
			comments = withComments;
			exclusive = excC14N;
			state = XmlCanonicalizerState.BeforeDocElement;
			visibleNamespaces = new ArrayList ();
			prevVisibleNamespacesStart = 0;
			prevVisibleNamespacesEnd = 0;
		}
コード例 #6
0
 public XmlCanonicalizer(bool withComments, bool excC14N)
 {
     res                        = new StringBuilder();
     comments                   = withComments;
     exclusive                  = excC14N;
     state                      = XmlCanonicalizerState.BeforeDocElement;
     visibleNamespaces          = new ArrayList();
     prevVisibleNamespacesStart = 0;
     prevVisibleNamespacesEnd   = 0;
 }
コード例 #7
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));
        }
コード例 #8
0
		// 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);
			}
		}
コード例 #9
0
		private void WriteDocumentNode (XmlNode node)
    		{
			state = XmlCanonicalizerState.BeforeDocElement;
			for (XmlNode child = node.FirstChild; child != null; child = child.NextSibling)
				WriteNode (child);
		}