Commits

Kevin Berridge committed ea33c46

Adds new constructor for XmlTextReader
XmlTextReader supports advanced options for dealing with xml namespaces (like ignoring ones that are undefined).

Comments (0)

Files changed (3)

SimpleXml/SimpleXml.cs

 using System.Xml.Linq;
 using System.IO;
 using System.Dynamic;
+using System.Xml;
 
 namespace SimpleXmlNs
 {
       elements = new List<XElement> { XElement.Load(reader) };
     }
 
+    public SimpleXml(XmlTextReader xmlReader)
+    {
+      elements = new List<XElement> { XElement.Load(xmlReader) };
+    }
+
     public SimpleXml(XElement element)
     {
       this.elements = new List<XElement> { element };

SimpleXmlTests/SimpleXmlReading.cs

 using NUnit.Framework;
 using System.IO;
 using SimpleXmlNs;
+using System.Xml;
 
 namespace SimpleXmlTests
 {
       Assert.Contains("value2", matches);
       Assert.Contains("value2", matches);
     }
+
+    [Test]
+    public void WithPrefixesWithNoXmlns()
+    {
+      var nameTable = new NameTable();
+      var nameSpaceManager = new XmlNamespaceManager(nameTable);
+      nameSpaceManager.AddNamespace("log4j", "urn:ignore");
+      var parserContext = new XmlParserContext(null, nameSpaceManager, null, XmlSpace.None);
+      var txtReader = new XmlTextReader(XmlStrings.PrefixesWithNoXmlns, XmlNodeType.Element, parserContext);
+
+      dynamic x = new SimpleXml(txtReader);
+
+      Assert.AreEqual("myMachine", x.@event.properties.data.value[0]);
+    }
   }
 }

SimpleXmlTests/XmlStrings.cs

         return "<h:section xmlns:h=\"http://www.w3.org/HTML/1998/html4\"><h:title>Blogs</h:title></h:section>".AsSimpleXml();
       }
     }
+
+    public static string PrefixesWithNoXmlns
+    {
+      get
+      {
+        return
+@"<log4j:event logger=""MyApp"" timestamp=""1219434607289"" level=""INFO"" thread=""4656"">
+    <log4j:message>my message</log4j:message>
+    <log4j:properties>
+        <log4j:data name=""log4jmachinename"" value=""myMachine""/>
+        <log4j:data name=""log4net:HostName"" value=""myHost""/>
+        <log4j:data name=""log4net:UserName"" value=""myUser""/>
+        <log4j:data name=""log4japp"" value=""myAppexe""/>
+    </log4j:properties>
+    <log4j:locationInfo class=""myClass"" method=""myMethod"" file=""C:\myApp\myFile.cs"" line=""266""/>
+</log4j:event>";
+      }
+    }
   }
 }