Using ASP.NET AJAX is there a control to display XML\JSON code?

1 Answer 77 Views
General Discussions
Brian
Top achievements
Rank 1
Brian asked on 28 Jul 2023, 09:17 PM

Using ASP.NET AJAX is there a control to display XML\JSON code? Formatted and colored?

 

Thanks Brian

1 Answer, 1 is accepted

Sort by
0
Accepted
Neha
Top achievements
Rank 2
Iron
Iron
answered on 30 Jul 2023, 10:28 PM

One popular library that you can use to display formatted and colored XML or JSON code is highlight.js. Highlight.js is a client-side JavaScript library that supports syntax highlighting for various programming languages, including XML and JSON. It can be easily integrated into your ASP.NET AJAX application to make the XML or JSON code more readable and visually appealing.

here is an ex:

Download the Highlight.js library or use a CDN link to include it in your web page.


<!-- Using CDN link -->
<script src="https://cdn.jsdelivr.net/npm/highlight.js@11.3.1/lib/highlight.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.3.1/styles/default.min.css">


Add CSS Styling: Optionally, add custom CSS styling to modify the appearance of highlighted code if needed.

Highlight XML/JSON Code: Use JavaScript to find the XML or JSON code elements in your web page and apply syntax highlighting using highlight.js.


<pre><code class="xml">
  <!-- Your XML code here -->
</code></pre>

<pre><code class="json">
  // Your JSON code here
</code></pre>

Finally, call the highlightAll() function to initialize Highlight.js and apply syntax highlighting to all code elements with the specified class.


<script>
  document.addEventListener('DOMContentLoaded', (event) => {
    hljs.highlightAll();
  });
</script>

The code above will automatically highlight all XML and JSON code blocks with the respective classes.
Brian
Top achievements
Rank 1
commented on 30 Jul 2023, 10:32 PM

Thank you for the response. I have played with this library. Was just wondering if there was a control with highlighting built in. I will use the library. Have a great day :)
Neha
Top achievements
Rank 2
Iron
Iron
commented on 30 Jul 2023, 10:47 PM

You're welcome! As of my knowledge ASP.NET AJAX does not have a built-in control specifically designed for displaying and highlighting XML or JSON code. The highlight.js library is a popular choice for adding syntax highlighting to code blocks on web pages,

If you have any more questions feel free to ask.

Have a great day too! Happy coding!

Rumen
Telerik team
commented on 31 Jul 2023, 06:40 AM

Yes, I can confirm that there isn't an XML editor in the Telerik ASP.NET AJAX framework. There is a workaround to configure RadEditor to display XML in Design and HTML mode, but it is with the help of other libraries and not a built-in feature.
Tags
General Discussions
Asked by
Brian
Top achievements
Rank 1
Answers by
Neha
Top achievements
Rank 2
Iron
Iron
Share this question
or