redhat-developer / redhat-developer/vscode-xml

Validation / intellisense using XSDs with same namespace

Open
#1,030 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
328
Forks
101
Avg merge
1d 17h
Merged PRs (30d)
7

Description

Hi,

I have two XSDs with same namespace:

document.a.1.0.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0" xmlns="urn:xsd:document.a.1.0" targetNamespace="urn:xsd:document.a.1.0">
  <xs:element name="Document" type="DocumentType"></xs:element>
  <xs:complexType name="DocumentType">
    <xs:sequence>
      <xs:element name="A1" type="xs:string" fixed="1"></xs:element>
      <xs:element name="A2" type="A2Type"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="A2Type">
    <xs:sequence>
      <xs:element name="A3" type="xs:string" fixed="3"></xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

document.a.1.0.add.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" version="1.0" xmlns="urn:xsd:document.a.1.0" targetNamespace="urn:xsd:document.a.1.0">
  <xs:element name="Document" type="DocumentType"></xs:element>
  <xs:complexType name="DocumentType">
    <xs:sequence>
      <xs:element name="A1" type="xs:string" fixed="2"></xs:element>
      <xs:element name="A2" type="A2Type_2"></xs:element>
    </xs:sequence>
  </xs:complexType>
  <xs:complexType name="A2Type_2">
    <xs:sequence>
      <xs:element name="A3" type="xs:string" fixed="33"></xs:element>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

And I generally use validation using catalog. For this XSD's I have the following entries in catalog.

catalog.xml

<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
  <system systemId="document.a.1.0.xsd" uri="document.a.1.0.xsd" />
  <system systemId="document.a.1.0.add.xsd" uri="document.a.1.0.add.xsd" />
  <uri name="urn:xsd:document.a.1.0" uri="document.a.1.0.xsd" />
  <uri name="urn:xsd:document.a.1.0" uri="document.a.1.0.add.xsd" />
</catalog>

The validation of the following XML passes in VsCode using this extension (I would say due to order of XSDs in catalog):

<?xml version="1.0" encoding="UTF-8"?>
<p:Document xmlns:p="urn:xsd:document.a.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <p:A1>1</p:A1>
  <p:A2>
    <p:A3>3</p:A3>
  </p:A2>
</p:Document>

But, this one fails:

<?xml version="1.0" encoding="UTF-8"?>
<p:Document xmlns:p="urn:xsd:document.a.1.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <p:A1>2</p:A1>
  <p:A2>
    <p:A3>33</p:A3>
  </p:A2>
</p:Document>

When I do validation in Java code I must choose the correct XSD to validate XML.
The issue may be related to XERCESJ-1130.

Is there a way to do the similar in VsCode, keeping the catalog as-is, but choose correct XSD?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the catalog.xml entries and the two schemas, document.a.1.0.xsd and document.a.1.0.add.xsd, then reproduce validation and IntelliSense behavior in VS Code using the two sample XML documents. Determine how a schema is selected when both URI mappings use the same namespace; done means users can choose the intended XSD without changing the catalog.

Written by the indexing model from the issue text.

Assessment

Tech stack
xml
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.