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 7419343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:03:12+00:00 2026-05-29T08:03:12+00:00

I have written a web-service (in Java) which produces as a result a (rather

  • 0

I have written a web-service (in Java) which produces as a result a (rather complex) XML document.

I’m required to return an HTML rendering of the document, if requested. Doesn’t have to be fancy, displaying the XML source with some basic formatting such as correctly indenting elements would do.

How do I do this?

  • 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-29T08:03:14+00:00Added an answer on May 29, 2026 at 8:03 am

    I agree, XSL would be the best approach. If you want to turn it into something that actually looks like XML, but just inside HTML, you could use something like this:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <!-- Evaluate Attributes -->
        <xsl:template match="@*">
            <span class="attribute">
                <span class="name">
                    <xsl:value-of select="name()"/>
                </span>="<span class="value"><xsl:value-of select="." /></span>"
            </span>
        </xsl:template>
    
    
        <!-- Evaluate Elements -->
        <xsl:template match="*" priority="10">
            <div class="element">
                <!-- First, create the opening tag with the attributes -->
                &lt;<span class="name"><xsl:value-of select="name()"/></span><xsl:apply-templates select="@*"/>&gt;
                <!-- Then, add children -->
                <xsl:apply-templates select="node()"/>
                <!-- Finally, add the closing tag -->
                &lt;/<span class="name"><xsl:value-of select="name()"/></span>&gt;
            </div>
        </xsl:template>
    
    
        <!-- Just copy everything else (text, comments, etc.) -->
        <xsl:template match="node()">
            <xsl:copy>
                <xsl:apply-templates select="@*|node()"/>
            </xsl:copy>
        </xsl:template>
    </xsl:stylesheet>
    

    And throw in some CSS:

    .element{margin-left:4em;font-size:14px;}
    .element .name{color:blue;}
    .attribute{margin-left:8px}
    

    UPDATE:

    <!-- Root node -->
    <xsl:template match="/">
        <div class="element">
            &lt;<span class="name"><xsl:value-of select="name()"/></span><xsl:apply-templates select="@*"/>
            <!-- Grab all namespaces and declare them.  distinct-values() is XPath 2.0, however. -->
            <xsl:for-each select="distinct-values(//namespace::*)">
                xmlns:<xsl:value-of select="name()" />="<xsl:value-of select="." />"
            </xsl:for-each>
            &gt;
            <xsl:apply-templates select="node()"/>
            &lt;/<span class="name"><xsl:value-of select="name()"/></span>&gt;
        </div>
    </xsl:template>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one module written on Java - web service module which accepts request
I have written a simple HelloWorld web service. Which takes an ArrayList as parameter.
I have a web-service written in Java, hosted on an Axis2 / Tomcat /
I have web services written using java which interacts with the android application only
I have written REST web service in netbean IDE using jersey framework and java.
I have REST Web service written in Java. Now I want to disable Web
I have a Web Service written in Java. I want to send some strings
I have a Java web service to which I've linked from a Delphi 2007
I have written a service for JIRA(a web application runs in tomcat) which runs
I have written a Web Service in Java using axis2 and the POJO deployment

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.