Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Improved XML grammar binding and more in Red Hat VS Code XML extension 0.13.0

July 8, 2020
David Kwon
Related topics:
Developer toolsIDEsJava
Related products:
Developer Toolset

    Following closely on the huge 0.12.0 update, the new Red Hat XML extension for Visual Studio Code (VS Code) 0.13.0 release makes XML editing in VS Code even better. For this release, we focused on making it easier to bind and generate a new XML Schema Definition (XSD) or Document Type Definition (DTD) grammar file from an existing XML file. Other highlights include document link support for xsi:schemaLocation, XML catalog snippets, support for XML catalog path validation, and support for DTD SystemId file path completion.

    This article offers a quick review and demonstrates the new features in Red Hat's XML extension version 0.13.0 for VS Code. For the complete list of changes, see the changelog.

    Note: The XML extension for VS Code, version 0.13.0, which consumes the LemMinX XML language server, is available in the Visual Studio Code Marketplace.

    Binding and generating XSD and DTD grammars

    Developers have previously reported issues with correctly binding an XML file with an XSD or DTD grammar. With the 0.13.0 release, we have added snippets and quick fixes to make this binding easier. The XML extension for VS Code can also generate XSD and DTD grammars from an existing XML file, which provides a great starter setup for new XML files.

    The new snippets and quick fixes support two workflows.

    Create and bind a grammar for an existing XML file

    You have a non-empty XML file, and you wish to create and bind a grammar for it. You can now use a quick fix to bind the existing XML file to a to-be-generated XSD or DTD grammar file, as demonstrated in Figure 1.

    An animated demonstration shows the steps in the console to bind and generate a new XSD grammar (file.xsd) to a pre-existing XML file (file.xml).
    Figure 1: Use a quick fix to bind and generate a new XSD grammar to an existing XML file.

    Create an XML file from scratch

    In this case, you are creating an XML file from scratch, and you wish to create and bind a grammar file for it. With the new XML extension update, you can use snippets to create an XML starter template that binds to a grammar file, then use a quick fix to generate the grammar file itself.

    In the demo in Figure 2, we use the noNamespaceSchemaLocation snippet to insert the XML starter template, then use a quick fix to create the demo.xsd file with the generated XSD grammar.

    An animated demonstration shows how to use insert an XML starter template, use a snippet to bind an XSD grammar, and then use a a quick fix to generate the grammar.
    Figure 2: Use a snippet to bind an XSD grammar to an XML template, then use a quick fix to generate the grammar.
    Figure 2: Use a snippet to bind an XSD grammar, then use a quick fix to generate the grammar.

    The XML extension for VS Code now includes the following snippet prefixes to help bind a grammar:

    Snippet prefix Snippet content
    schemaLocation Bind to an XML grammar with xsi:schemaLocation.
    noNamespaceSchemaLocation Bind to an XML grammar with xsi:noNamespaceSchemaLocation.
    <!DOCTYPE Bind to a DTD grammar with PUBLIC DOCTYPE.
    Bind to a DTD grammar with PUBLIC DOCTYPE with a subset.
    Bind to a DTD grammar with SYSTEM DOCTYPE.
    Bind to a DTD grammar with SYSTEM DOCTYPE with a subset.

    Let's take a closer look at the schema generator and how it works for various scenarios.

    Characteristics of the schema generator

    When generating an XSD or DTD grammar based on pre-existing XML content, the generator accounts for the element and attribute context. Consider the following examples.

    Required attribute: Every element instance contains a certain attribute

    If the XML content contains a certain attribute in each instance of a particular element, the grammar generator will consider this attribute to be required.

    Here is the initial XML content:

    <root>
    	<item attr="value" />
    	<item attr="value" />
    	<item attr="value" />
    </root>

    Here is the generated XSD attribute:

    <xs:attribute name="attr" use="required" />

    Here is the generated DTD attribute:

    <!ATTLIST item attr NMTOKEN #REQUIRED>

    Fixed attribute value: The same attribute value occurs five or more times

    If the XML content contains an attribute with the same value appearing five or more times, the grammar generator will consider the value to be a fixed value.

    Here is the XML content:

    <root>
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    </root>
    

    Here is the generated XSD attribute:

    <xs:attribute name="attr" use="required" fixed="A" />

    Here is the generated DTD attribute:

    <!ATTLIST item attr NMTOKEN #FIXED "A">

    ID attribute value: There are 10 or more unique attribute values

    If every instance of an element contains an attribute with at least 10 unique attribute values, the grammar generator will consider this attribute to be an ID specifier.

    Here is the XML content:

    <root>
    	<item attr="id1" />
    	<item attr="id2" />
    	<item attr="id3" />
    	<item attr="id4" />
    	<item attr="id5" />
    	<item attr="id6" />
    	<item attr="id7" />
    	<item attr="id8" />
    	<item attr="id9" />
    	<item attr="id10" />
    </root>
    

    Here is the generated XSD attribute:

    <xs:attribute name="attr" type="xs:ID" use="required" />

    Here is the generated DTD attribute:

    <!ATTLIST item attr ID #REQUIRED>

    Attribute enum value: The same set of attribute values is used repeatedly

    If the same set of distinct attribute values is used repeatedly, the grammar generator will consider these values to be enum values, therefore enforcing the possible values to be from the set. Enum values will only be generated if the attribute occurs at least 10 times, and only if the number of occurrences divided by the number of distinct values is greater than or equal to three.

    Here is the XML content:

    <root>
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="A" />
    	<item attr="B" />
    	<item attr="B" />
    	<item attr="B" />
    	<item attr="B" />
    	<item attr="B" />
    </root>
    <!-- Attribute ‘attr’ occurs 10 times, with 2 distinct values -->
    <!-- (10 / 2) = 5 >= 3 -->
    

    Here is the generated XSD attribute:

    <xs:attribute name="attr" use="required">
      <xs:simpleType>
        <xs:restriction base="xs:string">
          <xs:enumeration value="A" />
          <xs:enumeration value="B" />
        </xs:restriction>
      </xs:simpleType>
    </xs:attribute>

    Here is the generated DTD attribute:

    <!ATTLIST item attr (A|B) #REQUIRED>

    Document link for the schema location

    The XML schema file specified in the xsi:schemaLocation is now a document link, meaning that you can Ctrl+click on the file name to quickly open it within VS Code. The demo in Figure 3 shows this action on the xsi:schemaLocation document link.

    An animated demo shows what happpens when you Ctrl+click the document link for xsi:schemaLocation.
    Figure 3: Ctrl+clicking on note.xsd opens the file in a new editor tab.
    Figure 3: Ctrl+clicking on note.xsd opens the file in a new editor tab.

    XML catalog snippets

    We have added three catalog snippets to assist you in creating new catalogs from scratch:

      Snippet prefix   Snippet content
    <catalog A new catalog without XSD or DTD.
    A new catalog bound using XSD.
    A new catalog bound using DTD.

    The demo in Figure 4 shows these catalog snippets being displayed in an empty file.

    An animated demo shows the new catalog snippets in an empty file.
    Figure 4: The new catalog snippets displayed in an empty file.
    Figure 4: The new catalog snippets displayed in an empty file.

    XML catalog path validation

    The XML extension for VS Code now verifies whether a path provided in the xml.catalogs setting refers to an existing file. If one or more file paths do not exist, a notification lists the invalid path(s). At that point, you are provided a convenient button to navigate to the xml.catalogs setting within the settings editor. (The button is especially useful when the settings editor is not open.)

    In Figure 5, the first entry is an existing file, while the second and third are not. The XML extension issues an error notification for each invalid file path.

    An animated demo shows one entry for an existing file and two that are invalid. When the XML extension detects the invalid file paths, it issues error notifications on those paths.
    Figure 5: The XML extension issues error notifications for invalid file paths.
    Figure 5: The XML extension issues error notifications for invalid file paths.

    DTD SystemId file path completion

    File paths now appear as completion options within the DTD SystemId property. As demonstrated in Figure 6, the completion options appear for both absolute and relative paths.

    An animated demo shows a DTD SystemId filepath completion.
    Figure 6: The XML extension completes a DTD SystemId file path.

    Moving forward

    This wraps up the highlights of the Red Hat XML extension for VS Code 0.13.0 release. For future releases, we plan to provide more robust and configurable formatting support for XML documents. As always, please feel free to open a GitHub issue or feature request, and let us know what we should address in the next release. Thank you for reading and stay tuned for more features and improvements!

    Further information

    • The XML extension for VS Code, version 0.13.0, is now available in the Visual Studio Code Marketplace.
    • Explore the vscode-xml extension and the underlying XML language server, LemMinX on GitHub.
    • Visit the XML extension for VS Code changelog.
    • Open a GitHub issue to let us know about bugs or new feature requests.
    Last updated: November 8, 2023

    Recent Posts

    • Protect data offloaded to GPU-accelerated environments with OpenShift sandboxed containers

    • Case study: Measuring energy efficiency on the x64 platform

    • How to prevent AI inference stack silent failures

    • Preventing GPU waste: A guide to JIT checkpointing with Kubeflow Trainer on OpenShift AI

    • How to manage TLS certificates used by OpenShift GitOps operator

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    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
    © 2026 Red Hat

    Red Hat legal and privacy links

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

    Chat Support

    Please log in with your Red Hat account to access chat support.