
In previous section, we mentioned about how to export an XML file from Excel. If you haven’t read it, you can do so by clicking this link. After we created our XML file, the next step can be a control step. In order to control an XML file, one of the ways of doing it is writing an XSD file. Indeed, we already made a definition for XSD that XSD checks the values on an XML. These checks can be a data type check or a value range check. Moreover, there can be other types of checks. If you are more curious about XSD, you can go and read this Wikipedia article. In this section, we will be concentrating more on how to use an XSD file in data validation and in our case that will be our XML file which we exported in previous section.
How Do We Use an XSD File in Data Validation?
In order to check an XML file, you need to give a link to your XML file that contains XSD file’s path in your computer. Having done that, your XML file can find the related XSD file and apply rules in it to itself. Here is the XML file we prepared along with previous sections;
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<EmployeeTable xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="TestXMLfile.xsd">
<EmployeeRow>
<EmployeeName>Elleanor Carter</EmployeeName>
<Age>130</Age>
<StartDate>05/05/2020</StartDate>
<AnnualIncome currency="GBP">45000</AnnualIncome>
<Department>IT</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Denzel Castillo</EmployeeName>
<Age>23</Age>
<StartDate>01/01/2020</StartDate>
<AnnualIncome currency="GBP">22000</AnnualIncome>
<Department>Sales</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Rosemarie Bevan</EmployeeName>
<Age>12</Age>
<StartDate>02/02/2020</StartDate>
<AnnualIncome currency="GBP">20000</AnnualIncome>
<Department>Marketing</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Callam Little</EmployeeName>
<Age>45</Age>
<StartDate>2020/07/07</StartDate>
<AnnualIncome currency="DZD">23500</AnnualIncome>
<Department>HR</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Mylie Mercado</EmployeeName>
<Age>2</Age>
<StartDate>03/03/2020</StartDate>
<AnnualIncome currency="EUR">24500</AnnualIncome>
<Department>IT</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Shelley Keenan</EmployeeName>
<Age>96</Age>
<StartDate>04/04/2020</StartDate>
<AnnualIncome currency="GBP">12500</AnnualIncome>
<Department>IT</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Jonathon Herring</EmployeeName>
<Age>32</Age>
<StartDate>01/01/2020</StartDate>
<AnnualIncome currency="GBP">500</AnnualIncome>
<Department>HR</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Dhruv Marsh</EmployeeName>
<Age>33</Age>
<StartDate>01/01/2020</StartDate>
<AnnualIncome currency="GBP">600</AnnualIncome>
<Department>HR</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Tommy Burton</EmployeeName>
<Age>34</Age>
<StartDate>01/01/2020</StartDate>
<AnnualIncome currency="GBP">100</AnnualIncome>
<Department>IT</Department>
</EmployeeRow>
<EmployeeRow>
<EmployeeName>Percy Jacobs</EmployeeName>
<Age>60</Age>
<StartDate>1999/02/02</StartDate>
<AnnualIncome currency="DZD">60005.5</AnnualIncome>
<Department>Marketing</Department>
</EmployeeRow>
</EmployeeTable>
As you can see in the third line, there is an important key-value as shown below;
xsi:noNamespaceSchemaLocation="TestXMLfile.xsd"
This line specifies that your XML file can find the related XSD file in the same directory as in its directory. In the next section, we will create an XSD file, so that we can get our XML file validated.
Note: You can also check this blog post and some other interesting topics on my personal web page.
Next: Step by Step: How to Create an XSD File to Validate Data in XML?