Skip to main content
Redhat Developers  Logo
  • Products

    Featured

    • Red Hat Enterprise Linux
      Red Hat Enterprise Linux Icon
    • Red Hat OpenShift AI
      Red Hat OpenShift AI
    • Red Hat Enterprise Linux AI
      Linux icon inside of a brain
    • Image mode for Red Hat Enterprise Linux
      RHEL image mode
    • Red Hat OpenShift
      Openshift icon
    • Red Hat Ansible Automation Platform
      Ansible icon
    • Red Hat Developer Hub
      Developer Hub
    • View All Red Hat Products
    • Linux

      • Red Hat Enterprise Linux
      • Image mode for Red Hat Enterprise Linux
      • Red Hat Universal Base Images (UBI)
    • Java runtimes & frameworks

      • JBoss Enterprise Application Platform
      • Red Hat build of OpenJDK
    • Kubernetes

      • Red Hat OpenShift
      • Microsoft Azure Red Hat OpenShift
      • Red Hat OpenShift Virtualization
      • Red Hat OpenShift Lightspeed
    • Integration & App Connectivity

      • Red Hat Build of Apache Camel
      • Red Hat Service Interconnect
      • Red Hat Connectivity Link
    • AI/ML

      • Red Hat OpenShift AI
      • Red Hat Enterprise Linux AI
    • Automation

      • Red Hat Ansible Automation Platform
      • Red Hat Ansible Lightspeed
    • Developer tools

      • Red Hat Trusted Software Supply Chain
      • Podman Desktop
      • Red Hat OpenShift Dev Spaces
    • Developer Sandbox

      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
    • Secure Development & Architectures

      • Security
      • Secure coding
    • Platform Engineering

      • DevOps
      • DevSecOps
      • Ansible automation for applications and services
    • Automated Data Processing

      • AI/ML
      • Data Science
      • Apache Kafka on Kubernetes
      • View All Technologies
    • Start exploring in the Developer Sandbox for free

      sandbox graphic
      Try Red Hat's products and technologies without setup or configuration.
    • Try at no cost
  • Learn

    Featured

    • Kubernetes & Cloud Native
      Openshift icon
    • Linux
      Rhel icon
    • Automation
      Ansible cloud icon
    • Java
      Java 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

    • API Catalog
    • Product Documentation
    • Legacy Documentation
    • Red Hat Learning

      Learning image
      Boost your technical skills to expert-level with the help of interactive lessons offered by various Red Hat Learning programs.
    • Explore Red Hat Learning
  • 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

Improved schema binding and more in Red Hat XML extension for VS Code 0.12.0 and LemMinX

July 2, 2020
David Thompson
Related topics:
Developer ToolsIDEsJava
Related products:
Developer Tools

Share:

    The latest update of the Red Hat XML extension for Visual Studio Code (VS Code), version 0.12.0, is packed with bug fixes and new features. It includes the new version of the underlying Eclipse LemMinX XML language server. In this update, we streamlined the process of writing XML Schema Definitions (XSD) and Document Type Definitions (DTD). We also added shortcuts to bind XML documents to either of these types of XML grammar.

    This article demonstrates the highlights of the 0.12.0 update to XML extension for VS Code, including new formatting options to reduce visual clutter, support for <?xml-model … ?>, and context-aware snippets to assist with binding a document to an XML schema. For the full list of more than 50 enhancements and bug fixes, see the XML extension for VS Code changelog. You can also watch a video demonstration of the new features here:

    Note: Both the XML extension for VS Code, version 0.12.0, and the underlying LemMinX XML language server are now available in the Visual Studio Code Marketplace.

    Entity validation and completion

    Red Hat's XML extension for VS Code now supports entity validation and entity-name completion with hover-over and go-to definitions for locally and externally declared entities.

    Hovering over an entity displays the value that it represents and a link to the file where it was defined. Going to the entity definition brings the cursor to the line in the file where the entity was declared, whether that’s in the same file or an external file. If an entity is referenced but hasn’t yet been declared, you can use the new quick fix to define it in the doctype declaration. All of these options are demonstrated in Figure 1.

    A demo of the new new entity validation, completion, hover, and go-to definitions.
    Figure 1: The new entity validation and completion features with hover-over and go-to definitions.

    XSD documentation settings

    Prior to this release, hovering over an XSD element displayed all of the xs:documentation and xs:appinfo available for that element on a single line, along with a link to the XSD schema file. With this release, we introduced a new setting to help remove some of that visual clutter, as shown in Figure 2.

    The VSCode settings menu, displaying the different options available for displaying XSD documentation
    Here are the options available for displaying XSD element documentation
    Figure 2: New options for displaying the XSD element documentation.

    You can now use the xml.preferences.showSchemaDocumentationType setting to specify what you would like to see when you hover over an element: xs:documentation, xs:appinfo, both of these elements, or nothing at all. Also, as shown in Figure 3, subtitles now separate the xs:documentation and xs:appinfo elements when they are both present, making definitions easier to read.

    Before and after for hovering over an element with documentation. The hover now seperates appinfo and documentation using subtitles
    Hovering over which has xs:documentation and xs:appinfo in its XSD schema declaration while xml.preferences.showSchemaDocumentationType is set to all
    Figure 3: The hover feature now uses subtitles to separate app info and documentation.

    Formatting (xml.format)

    We introduced several new settings to the XML extension's formatting feature.

    Enforce quote style: Ignore or preferred

    The xml.format.enforceQuoteStyle setting indicates that the formatter should replace all quotations with the preferred quotation type (which is set in xml.preferences.quoteStyle) or ignore the preferred quotation type and leave the quotes as they are (which is the default setting). The demonstration in Figure 4 shows the new quote-style options.

    A demonstration of the formatter ignoring the preferred format style when enforceQuoteStyle is set to be ignored.
    Figure 4: The default Enforce Quote Style setting is to ignore the quote style.
    Figure 4: The default Enforce Quote Style setting is to ignore the quote style.

    Empty elements: Ignore, collapse, or expand

    The xml.format.emptyElements setting tells the formatter whether to write empty elements using an opening and closing tag (<img></img>), or using the shorthand notation (<img />). As a default setting, you can choose to preserve the format that is already in use. The demo in Figure 5 shows these options.

    Demo of the formatter expanding self-closing elements and turning self closing elements into an open and close tag, depending on the emptyElements setting.
    Figure 5: The formatter can expand or turn off self-closing elements depending on the Empty Elements setting.

    Preserve attribute line breaks: True or false

    If you enable the xml.format.preserveAttributeLineBreaks setting, the formatter will preserve line breaks before and after attributes. By default, the formatter places each attribute on a single line, so this setting is useful for indicating that attributes should stay on their respective lines. The demo in Figure 6 shows the formatter placing line breaks before and after attributes.

    A demonstration of the formatter preserving line breaks between attributes.
    Figure 6: The formatter can preserve line breaks before and after attributes.
    Figure 6: The formatter can preserve line breaks before and after attributes.

    Document links

    Navigating between XML documents and their schemas is easier in the new XML extension for VS Code. The extension now provides document links in the schemaLocation attribute for the xs:include and xs:import schema elements, as well as another document link in the href attribute for the xml-model processing instruction. Figure 7 shows an xs:schema with xs:include and xs:import elements.

    An xs schema with xs include and xs import, showing the underlined document links

    New XML model support

    The XML extension for VS Code now supports the <?xml-model … ?> method of binding an XML document to its schema. The XML document will be validated against the schema, providing all the same features that are already supported through existing methods of schema binding. We added a document link that links the href attribute of the <?xml-model … ?> instruction to the referenced schema document. As discussed in the next section, we also added snippets to help with writing the XML model schema references.

    Figure 8 shows a demonstration of an XML document being bound to an .xsd document through the <?xml-model … ?> processing instruction.

    A demonstration of an XML document being bound to an xs document through the xml-model processing instruction.
    Figure 8: An XML document is bound to an <code>.xsd</code> document through the <code>&lt;?xml-model … ?&gt;</code> processing instruction.

    Snippets

    We made several changes to improve snippets. Previously, snippets were a part of the XML extension for VS Code. With this update, we moved them to the server-side of the extension (LemMinX) using the JSON format. Not only does this change allow us to provide snippets to all of the Language Server Protocol (LSP) clients (such as Eclipse with Wild Web Developer, Emacs, and so on) but snippets are context-aware. For example, we can provide XML declaration snippets only if the document does not already have an XML declaration, and only if your cursor is on the first line of the document. We also added new snippets, such as for doctype declarations. The overall goal of adding these snippets is to make it easier to bind documents to schemas.

    Snippet demos

    The demo in Figure 9 shows some of the possible snippet completions.

    An empty file showing many possible snippet completions
    Here are several examples of the snippets now available in the new VS Code XML extension update
    Figure 9: Examples of snippets now available in the new XML extension for Visual Studio Code.

    In Figure 10, we use snippets to quickly create an XML document bound to .xsd schemas through schemaLocation and noNamespaceSchemaLocation. We then use a snippet to write an XML document with a doctype declaration.

    A demo that shows snippets that automatically generate schema bindings in blank XML files.

    In Figure 11, we use a snippet to quickly generate a doctype declaration that declares the root element of the XML document.

    A demo of using a snippet to generate a doctype declaration for an existing XML file.
    Figure 11: Using snippets to generate a doctype declaration.

    In a future release, we hope to provide snippets and quick fixes that generate schemas from existing XML documents.

    A new outline limit for symbols

    For performance reasons, we set a default limit of 6,000 symbol-tree items for the Outline view, which is located within the XML extension's Explorer. You can use the use xml.symbols.maxItemsComputed setting to manually configure the limit.

    When the symbol limit is reached for a particular file, a notification will appear, providing the current limit and a Configure Limit button, which navigates to the xml.symbols.maxItemsComputed setting in the VS Code settings UI. Figure 12 shows the error and the new button.

    VSCode displays an error message when the document symbol limit is exceeded
    A large file, file.xml has been opened. Since file.xml contains more than 6000 elements, the symbols tree has been capped at 6000 items.
    Figure 12: A large file with the symbols tree capped at 6,000 items.

    Conclusion

    Our goal with the 0.12.0 version of Red Hat's XML extension for Visual Studio Code was to improve the workflow of writing XML schemas and binding XML documents to a grammar. For the next release, we aim to improve the schema-writing workflow by providing quick fixes and snippets that make it easier to generate the schema for a particular XML document. If you encounter unexpected behavior in this release, feel free to open a GitHub issue.

    Note: Special thanks to Balduin Landolt, who contributed the <?xml-model … ?> snippets, as well as a fix that disables snippets if the cursor is before the XML prolog.

    Further information

    • Get the vscode-xml extension on the Visual Studio Marketplace.
    • Get the vscode-xml extension on GitHub.
    • Check out LemMinX, the XML Language Server on GitHub.
    • Open a new issue on the LemMinX GitHub page.
    • View the changelog for LemMinX.
    • Learn more about LemMinX being migrated to the Eclipse Foundation.
    OSZAR »
    Last updated: February 5, 2024

    Recent Posts

    • More Essential AI tutorials for Node.js Developers

    • How to run a fraud detection AI model on RHEL CVMs

    • How we use software provenance at Red Hat

    • Alternatives to creating bootc images from scratch

    • How to update OpenStack Services on OpenShift

    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

    Red Hat legal and privacy links

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

    Report a website issue

    OSZAR »