Skip to main content
Redhat Developers  Logo
  • Products

    Platforms

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat AI
      Red Hat AI
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • View All Red Hat Products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat Developer Hub
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat OpenShift Local
    • Red Hat Developer Sandbox

      Try Red Hat products and technologies without setup or configuration fees for 30 days with this shared Openshift and Kubernetes cluster.
    • Try at no cost
  • Technologies

    Featured

    • AI/ML
      AI/ML Icon
    • Linux
      Linux Icon
    • Kubernetes
      Cloud icon
    • Automation
      Automation Icon showing arrows moving in a circle around a gear
    • View All Technologies
    • Programming Languages & Frameworks

      • Java
      • Python
      • JavaScript
    • System Design & Architecture

      • Red Hat architecture and design patterns
      • Microservices
      • Event-Driven Architecture
      • Databases
    • Developer Productivity

      • Developer productivity
      • Developer Tools
      • GitOps
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Secure Development & Architectures

      • Security
      • Secure coding
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • AI/ML
      AI/ML Icon
    • View All Learning Resources

    E-Books

    • GitOps Cookbook
    • Podman in Action
    • Kubernetes Operators
    • The Path to GitOps
    • View All E-books

    Cheat Sheets

    • Linux Commands
    • Bash Commands
    • Git
    • systemd Commands
    • View All Cheat Sheets

    Documentation

    • Product Documentation
    • API Catalog
    • Legacy Documentation
  • Developer Sandbox

    Developer Sandbox

    • Access Red Hat’s products and technologies without setup or configuration, and start developing quicker than ever before with our new, no-cost sandbox environments.
    • Explore Developer Sandbox

    Featured Developer Sandbox activities

    • Get started with your Developer Sandbox
    • OpenShift virtualization and application modernization using the Developer Sandbox
    • Explore all Developer Sandbox activities

    Ready to start developing apps?

    • Try at no cost
  • Blog
  • Events
  • Videos

How the new VSCode XML extension improves developer experience

November 29, 2022
Mohit Suman Angelo Zerr Jessica He
Related topics:
Developer ToolsOpen source
Related products:
Developer Tools

Share:

    At Red Hat, we look forward to creating and updating tools to improve the developer experience for users of various language servers. Visual Studio Code is one of the most popular tools for developers. The rich ecosystem of multiple extensions makes it more powerful.

    We are excited to announce the release of VSCode XML Extension 0.22.0 in Visual Studio Code Marketplace and OpenVSX Registry and the addition of more improvements and features to work with XML and improve the overall developer experience.

    A little VSCode XML history

    The VSCode team has continuously worked with the community and received user feedback and requests. It is interesting to see the evolution of the software based on these requests. The extension was originally created to manage pom.xml files of maven projects with the VSCode Java extension and provide XML and XSD support.

    VSCode XML uses the LemMinx language server written in Java to provide the various language features. However, this required Java installation. Over time, we received more and more requests from users to use the extension without Java. That's why we provided the binary feature to run the language server without Java.

    Because of multiple feature requests for RelaxNG support, we integrated Jing to implement RelaxNG support in the VSCode XML extension. This has been a great addition to the extension's feature list and has shown an upward trend in usage after the release.

    Since then, we have made multiple improvements. In this blog, we will focus on two important features added to the current release.

    1. RelaxNG support provides completion, hover, and validation in XML files based on RelaxNG schemas.
    2. We have made improvements to our experimental XML formatter.

    1. RelaxNG support

    RelaxNG support provides completion, hover, and validation in XML files based on RelaxNG schemas (XML syntax and compact syntax). Figure 1 explains the workflow:

    An illustration of relax-ng-support.
    Figure 1: The RelaxNG support workflow.

    Validation

    XML validation based on RelaxNG (rng and rnc) is supported as shown in Figure 2:

    An illustration xml-validation process based on RelaxNG.
    Figure 2: The XML validation process based on RelaxNG.

    Completion

    It supports XML completion based on RelaxNG (rng, rnc). The completion for rng displays the documentation in Figure 3:

    The xml-completion process based on RelaxNG.
    Figure 3: The XML completion process based on RelaxNG.

     

    Hover

    Hover based on RelaxNG rng shows the documentation in Figure 4:

    An illustration of xml-hover based on RelaxNG.
    Figure 4: Hover based on RelaxNG.

    Go to type definition

    From the XML document, you can go to the type definition to navigate to the element/attribute declaration for rnc and

    To do this, select an XML element/attribute and use the contextual menu Go to Type Definition as shown in Figure 5.

    The XML Go To Type Definition action.
    Figure 5: The XML Go To Type Definition action.

     

    When you click on this menu item, VS Code will open the rng or rnc grammar file and place the cursor on the proper element/attribute declaration as shown in Figure 6.

    An illustration of the xml-grammar file support.
    Figure 6: The XML grammar file support.

    2. The experimental formatter

    The current XML formatter works correctly when XML is valid. For instance, given the following XML content:

    <foo><bar></bar></foo>

    The XML is formatted like this:

    <foo>
    
      <bar></bar>
    
    </foo>

    But when XML content is invalid, as in the following example:

    <foo><bar'</bar></foo>

    The XML is formatted like the following:

    <foo>
    
      <bar

    The formatter will lose all the invalid content, which can be extremely annoying. It is one reason we re-implemented a formatter from scratch with a new strategy. Here is the invalid content from above reformatted with the new experimental formatter:

    <foo>
    
    <bar'</bar></foo>

    To activate the experimental formatter, set “xml > Format: Experimental” to “true” on the VS Code Settings Page or add the following to your settings.json:

    "xml.format.experimental": true

    This also opens the extension to the possibility of supporting XML with various embedded content within XML documents (eg. EJS).

    Our goal is to make this new formatter the default once it supports all features of the current formatter. Please don’t hesitate to create any issues to improve the experimental formatter.

    How the new formatter works

    The current formatter gets the DOM document, the abstract representation of the XML document that vscode-xml uses and rewrites the content of the document in one text edit:

    [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 0
                },
                "end": {
                    "line": 0,
                    "character": 22
                }
            },
            "newText": "<foo>\r\n\t<bar></bar>\r\n</foo>"
        }
    ]

    The new experimental formatter preserves all non-whitespace content and inserts or removes spaces to correctly indent the XML content. In the following sample, two TextEdit are generated. The insert/replace characters avoid losing invalid content.

    [
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 5
                },
                "end": {
                    "line": 0,
                    "character": 5
                }
            },
            "newText": "\r\n\t"
        },
        {
            "range": {
                "start": {
                    "line": 0,
                    "character": 16
                },
                "end": {
                    "line": 0,
                    "character": 16
                }
            },
            "newText": "\r\n"
        }
    ]
    

    New experimental formatter settings

    In addition to a list of default elements where whitespace will be preserved, users may choose to modify this with their own set of elements. Refer to the documentation preserve space page for more information.

    The following example shows two ways in which whitespaces will be preserved.

    (Note: XML remains the same after formatting.)

    Method #1: Figure 7 shows literallayout in the list of default elements where whitespaces will be preserved.

    The xml-literal-layout tag support.
    Figure 7: The literallayout tag support.

     

    Method #2: Figure 8 shows that any element with xml:space = “preserve” will preserve whitespaces.

    Preserve space support in XML.
    Figure 8: Preserve space support in XML.

     

    Support for the ability to set a maximum line width has been requested and upvoted by many users. Currently, this setting works with text content and comments. We are on track to extend this feature to cover other use cases such as attributes and ensure its behavior is consistent when applied in combination with other settings. Refer to the documentation for maximum line width formatting.

    The example in Figure 9 shows formatting with maxLineWidth set to the default value of 80.

    The XML max line width support.
    Figure 9: The XML max line width support.

     

    There are a growing number of use cases supported with this setting. This option enables the formatter to consider XML Schema/DTD grammar information when making decisions. For instance, an element defined as “xs:string” in the schema will preserve any whitespace in the content when formatting.

    For more information on the specific use cases, visit the official VSCode XML GitHub page.

    Contribute and get support

    This is an open-source project available to anyone. Contributions are extremely welcome! To get started, refer to the contributing instructions.

    If you encounter any bugs, confusing commands, or unclear documentation, or if you would like to propose a feature request, you can:

    • File a bug in GitHub Issues.
    • Chat with us on Gitter.
    • Review documentation on GitHub.
    • Refer to the Release Notes.

    We are actively working to improve the developer experience with XML. Stay tuned for more features coming soon!

    Last updated: November 8, 2023

    Related Posts

    • XML Language Server and the VSCode Extension

    • Preserving the Red Hat developer experience

    • How to create a better front-end developer experience

    Recent Posts

    • A deep dive into Apache Kafka's KRaft protocol

    • Staying ahead of artificial intelligence threats

    • Strengthen privacy and security with encrypted DNS in RHEL

    • How to enable Ansible Lightspeed intelligent assistant

    • Why some agentic AI developers are moving code from Python to Rust

    What’s up next?

    Path to GitOps cover card

    Read The Path to GitOps for a comprehensive look at the tools, workflows, and structures teams need to have in place in order to enable a complete GitOps workflow.

    Get the e-book
    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Products

    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform

    Build

    • Developer Sandbox
    • Developer Tools
    • Interactive Tutorials
    • API Catalog

    Quicklinks

    • Learning Resources
    • E-books
    • Cheat Sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site Status Dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2025 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Report a website issue