Beispiel #1
0
 public void ParseHtmlEntityInXmlShouldThrowError()
 {
     var source = @" <title>&nbsp;</title>";
     var parser = new XmlParser();
     Assert.Catch<XmlParseException>(() =>
     {
         var document = parser.Parse(source);
     });
 }
Beispiel #2
0
        public void ParseHtmlStructureInXmlShouldThrowError()
        {
            var source = @" <title>My Title</title>
 <p>My paragraph</p>";
            var parser = new XmlParser();
            Assert.Catch<XmlParseException>(() =>
            {
                var document = parser.Parse(source);
            });
        }
Beispiel #3
0
 public void ParseInvalidXmlEntityShouldBeSerialized()
 {
     var source = @" <title>&nbsp;</title>";
     var parser = new XmlParser(new XmlParserOptions
     {
         IsSuppressingErrors = true
     });
     var document = parser.Parse(source);
     Assert.AreEqual("&nbsp;", document.DocumentElement.TextContent);
 }
Beispiel #4
0
 public void ParseValidXmlEntityShouldBeRepresentedCorrectly()
 {
     var source = @" <title>&amp;</title>";
     var parser = new XmlParser(new XmlParserOptions
     {
         IsSuppressingErrors = true
     });
     var document = parser.Parse(source);
     Assert.AreEqual("&", document.DocumentElement.TextContent);
 }
Beispiel #5
0
 public void ParseHtmlEntityInXmlShouldNotThrowErrorIfSuppressed()
 {
     var source = @" <title>&nbsp;</title>";
     var parser = new XmlParser(new XmlParserOptions
     {
         IsSuppressingErrors = true
     });
     var document = parser.Parse(source);
     Assert.AreEqual(1, document.Children.Length);
 }
Beispiel #6
0
        public void ParseHtmlStructureInXmlShouldNotThrowErrorIfSuppressed()
        {
            var source = @" <title>My Title</title>
 <p>My paragraph</p>";
            var parser = new XmlParser(new XmlParserOptions
            {
                IsSuppressingErrors = true
            });
            var document = parser.Parse(source);
            Assert.AreEqual(1, document.Children.Length);
        }
        public void ObtainElementPositionsFromXml()
        {
            var positions = new Dictionary<IElement, TextPosition>();
            var source = @"<hello>
   <foo />
   <bar>
      <test></test><test></test><test></test>
   </bar>
</hello>";
            var parser = new XmlParser(new XmlParserOptions
            {
                OnCreated = (element, position) => positions[element] = position
            });
            var document = parser.Parse(source);
            Assert.AreEqual(6, positions.Count);
        }
Beispiel #8
0
 public static IDocument ToXmlDocument(this String sourceCode, IConfiguration configuration = null)
 {
     var xmlParser = new XmlParser(configuration);
     return xmlParser.Parse(sourceCode);
 }