I have below XSD:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="https://www.w3schools.com"
xmlns="https://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="rootNode" type="records" />
<xs:complexType name="records">
<xs:sequence>
<xs:element name="element1" type="type-attrbute-grp" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="type-attrbute-grp">
<xs:attributeGroup ref="attribute-grp" />
</xs:complexType>
<xs:attributeGroup name="attribute-grp">
<xs:attribute name="scale" type="xs:int" use="required" />
<xs:attribute name="date" type="xs:date" use="required" />
</xs:attributeGroup>
</xs:schema>
And I have create below XML:
<?xml version="1.0" encoding="UTF-8"?>
<p:rootNode xmlns:p="https://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://www.w3schools.com test2.xsd ">
<p:element1 date="2001-01-01" scale="7"/>
</p:rootNode>
We can provide more information about an element with attributes. But, my question is can we provide meta data about attribute? My goal is to show "element1" in UI as a table row and "date"/"scale" as columns to the table. Also, I want to add some validations for scale and date columns and that information I want to provide in XSD. i.e. what validator should be applied to scale and what widget I want to show on scale cell? etc..
You can add your own meta data to most xsd entities. What you do with it is then up to the application consuming it.
In the following example the MyColumnInfo element has been attached to the scale attribute.
Most SOM (Schema object Model) parsers will allow you access to this information. But parsing schemas tends to be a bit tricky, so what seems like a quick job could rapidly turn into quite a big task.
In .Net you have the XsdSchema class which you can read the schema into and navigate it. In java you can use xerces.