Merge pull request #2566 from lambdageek/monoerror-mono_module_get_object
[mono.git] / mcs / class / corlib / Mono.Xml / SecurityParser.cs
index ad380a22fa7800acf5cb2f4cd4f9822a89138f0d..49919b9779d1c53fcba30ea571a8cad403cb5bfe 100644 (file)
@@ -32,6 +32,7 @@
 
 using System;
 using System.Collections;
+using System.IO;
 using System.Security;
 
 namespace Mono.Xml {
@@ -40,10 +41,9 @@ namespace Mono.Xml {
 #if INSIDE_CORLIB
        internal
 #else
-       [CLSCompliant(false)]    
        public
 #endif
-       class SecurityParser : MiniParser, MiniParser.IHandler, MiniParser.IReader {
+       class SecurityParser : SmallXmlParser, SmallXmlParser.IContentHandler {
 
                private SecurityElement root;
 
@@ -55,10 +55,8 @@ namespace Mono.Xml {
                public void LoadXml (string xml) 
                {
                        root = null;
-                       xmldoc = xml;
-                       pos = 0;
                        stack.Clear ();
-                       Parse (this, this);
+                       Parse (new StringReader (xml), this);
                }
 
                public SecurityElement ToXml () 
@@ -66,26 +64,18 @@ namespace Mono.Xml {
                        return root;
                }
 
-               // IReader
-
-               private string xmldoc;
-               private int pos;
-
-               public int Read () 
-               {
-                       if (pos >= xmldoc.Length)
-                               return -1;
-                       return (int) xmldoc [pos++];
-               }
-
-               // IHandler
+               // IContentHandler
 
                private SecurityElement current;
                private Stack stack;
 
-               public void OnStartParsing (MiniParser parser) {}
+               public void OnStartParsing (SmallXmlParser parser) {}
+
+               public void OnProcessingInstruction (string name, string text) {}
+
+               public void OnIgnorableWhitespace (string s) {}
 
-               public void OnStartElement (string name, MiniParser.IAttrList attrs) 
+               public void OnStartElement (string name, SmallXmlParser.IAttrList attrs) 
                {
                        SecurityElement newel = new SecurityElement (name); 
                        if (root == null) {
@@ -101,7 +91,7 @@ namespace Mono.Xml {
                        // attributes
                        int n = attrs.Length;
                        for (int i=0; i < n; i++)
-                               current.AddAttribute (attrs.GetName (i), attrs.GetValue (i));
+                               current.AddAttribute (attrs.GetName (i), SecurityElement.Escape (attrs.GetValue (i)));
                }
 
                public void OnEndElement (string name) 
@@ -111,9 +101,9 @@ namespace Mono.Xml {
 
                public void OnChars (string ch) 
                {
-                       current.Text = ch;
+                       current.Text = SecurityElement.Escape (ch);
                }
 
-               public void OnEndParsing (MiniParser parser) {}
+               public void OnEndParsing (SmallXmlParser parser) {}
        }
 }