Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6567175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:18:18+00:00 2026-05-25T14:18:18+00:00

The following test fails. r1 seems to be missing angle brackets, does anyone know

  • 0

The following test fails. r1 seems to be missing angle brackets, does anyone know way? I imagine its some sort of encoding error?

var nav1 = XElement.Load(stream).CreateNavigator(); 
var nav2 = new XPathDocument(stream).CreateNavigator();

using (var r1 = new StringWriter())
using (var r2 = new StringWriter())
{
  xslt.Transform(nav1, null, r1);
  xslt.Transform(nav2, null, r2);

  r1.ToString().Should().Equal(r2.ToString());
}

The problem here is not as far as I can tell semantically equivalent but lexically different xml, but that the resulting xml in the r1 case is missing it’s xml tags. Interestingly, using var nav3 = XElement.Load(stream).CreateReader(); works fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:18:19+00:00Added an answer on May 25, 2026 at 2:18 pm

    Comparing two XML documents using their string representation is not a good idea. While the two documents may be equivalent, they still could have many lexical differences, among them:

    • Different prefixes bound to the same namespace.
    • Use/not use CDATA sections
    • represent/not-represent as strings inherited namespace nodes
    • use quotes vs apostrophes
    • use vs not-use character entities.
    • …, etc.

    I would recommend a better way of doing this — there are many xmldiff tools. You could also build your own XML comparison tool (as I have done for myself) based on my answer to this question.

    UPDATE:

    After clarifications from the OP:

    "The problem here is not as far as I can tell semantically equivalent
    but lexically different xml, but that the resulting xml in the r1 case
    is missing it’s xml tags"

    I investigated and came up with the following conclusion:

    The XslCompiledTransform.Transform(IXPathNavigable, XsltArgumentList, Stream) works with either XmlDocument or XPathDocument as the first argument, as is described in the MSDN documentation.

    Parameters     
       inputType: System.Xml.XPath.IXPathNavigable An object    
                  implementing the IXPathNavigable interface. In the Microsoft .NET Framework, this
                  can  be either an XmlNode (typically an XmlDocument), or 
                  an XPathDocument containing the data to be transformed.
    

    As the Navigator created from an XElement obviously doesn’t fit in this category, the reported problem is observed.

    Solution:

    Change:

    var nav1 = XElement.Load(stream).CreateNavigator();
    

    to:

    var nav1 = XDocument.Load(stream).CreateNavigator();
    
          
    

    Here is complete code that has been verified to work as expected:

    using System.IO;
    using System.Xml.Linq;
    using System.Xml.XPath;
    using System.Xml.Xsl;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace TestLINQ_Xml
    {
        class Program
        {
            static void Main(string[] args)
            {
                test();
            }
    
            static void test()
            {
                XslCompiledTransform xslt = new XslCompiledTransform();
                xslt.Load(@"C:\temp\delete\XSLT.xsl");
    
                FileStream stream = 
                  new FileStream(@"C:\temp\delete\sourceXML.xml", FileMode.Open);
    
                var xdoc = XDocument.Load(stream);
                var nav1 = xdoc.CreateNavigator();
    
                stream.Seek(0L, SeekOrigin.Begin);
                var nav2 = new XPathDocument(stream).CreateNavigator(); 
    
                using (var r1 = new StringWriter()) using (var r2 = new StringWriter()) 
                {   xslt.Transform(nav2, null, r1); 
                    xslt.Transform(nav1, null, r2); 
    
                    string  res1 = r1.ToString();
                    string  res2 = r2.ToString();
    
                    Assert.AreEqual(res1, res2);
                } 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following test fails: #!/usr/bin/env python def f(*args): >>> t = 1, -1 >>>
Using NUnit 2.2 on .NET 3.5, the following test fails when using DateTime.Equals. Why?
The following test case fails in rhino mocks: [TestFixture] public class EnumeratorTest { [Test]
I've isolated the behaviour into the following test case. I'd be grateful to anyone
When I run the following test in Gallio's Icarus it passes, but when I
When my browser renders the following test case, there's a gap below the image.
I am testing against the following test document: <?xml version=1.0 encoding=UTF-8?> <!DOCTYPE html PUBLIC
I have written the following simple test in trying to learn Castle Windsor's Fluent
I've ran into a problem while trying to test following IRepository based on NHibernate:
in Javascript, the following: var test = 'the quick brown fox jumps over the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.