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

  • SEARCH
  • Home
  • 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 6059619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:43:55+00:00 2026-05-23T08:43:55+00:00

I am getting responses from two different web services in XML format. Both web

  • 0

I am getting responses from two different web services in XML format. Both web services have the same logic but developed in different technologies. We are shifting our web services to Microsoft Technology. The web service engine is the core which is connected to many other application and providing different services to them.

Whenever there is a call to a production web service, we pass a similar call to the web service which is developed on Microsoft Technologies and save both responses in separate folders.

Now, we have to compare both responses (XML). There are lot of sorting and intending issues. I would like to avoid all the sorting and indenting issues so I can get the right comparison report.

Is there a way you can sort and indent
XML before saving (XMLDocument.Save) it?

Thanks.


Solution:

I have found some XSLT that does that on the net, but there seems to be a
problem when the elements have attributes.

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-template select="@* | node()">
            <xsl:sort select="name()"/>
        </xsl:apply-template>
    </xsl:copy>
</xsl:template>

Indeed, attribute nodes have to be copied to the result tree before any nodes of another type. Because of the sorting, the node-set loses document order and thus cannot any longer guarantee that the attributes are processed earlier than the elements and text nodes.

one solution is this:

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@*">
            <xsl:sort select="name()"/>
        </xsl:apply-templates>
        <xsl:apply-templates select="node()">
            <xsl:sort select="name()"/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>

But since the relative output order of attributes after serialization of the result tree depends on the processor, you might as well omit the attribute sorting:

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates select="node()">
            <xsl:sort select="name()"/>
        </xsl:apply-templates>
    </xsl:copy>
</xsl:template>

Thanks Snoopy and others for their help!

  • 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-23T08:43:55+00:00Added an answer on May 23, 2026 at 8:43 am

    i recommend xmlunit for comparing the files, this nunit extension is written in c# and free.
    http://xmlunit.sourceforge.net/

    or do it like this if you prefer manual compares:

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("bla");
    XmlTextWriter writer = new XmlTextWriter("data.xml",null);
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two web application which are deployed in the same J2EE Application server.
I'm developing an axis java web service with two methods, both have an custom
I have an application which uses a web service to get data. Before getting
I have set up transactional replication between two SQL Servers on different ends of
I am getting the value from web service like &gt;&lt;&amp;&nbsp; etc. I want to
Let's start by getting on the same page about MVC on the web. The
I have two web pages; Foo.aspx and Bar.aspx. Bar.aspx uses jQuery.ajax() to request a
I'm getting a JSON response from the server and i have to loop through
I'm getting an Ajax response from a web service, and I'm not sure what
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for 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.