1
votes

I am trying to use XSD validation in Azure Data Factory copy activity (with XML as source). I have an external XSD file. I am also trying to understand how it can be used in Azure Data Factory. In the copy activity, under the Validation type section there are two options XSD and DTD. But, it does not have any way to specify any external file as XSD. The documentation is also not clear about this. (https://docs.microsoft.com/en-us/azure/data-factory/format-xml). This is what the official doc says:

XML schema validation:
You can choose to not validate schema, or validate schema using XSD or DTD.
When using XSD or DTD to validate XML files, the XSD/DTD must be referred inside the XML 
files through relative path

I am confused about the second point here.

What do they mean by "XML must be referred inside the XML files"?

1

1 Answers

4
votes

I think it says, we should reference the XSD file(use relative path) in the source xml file.

For example:
In the ADF I set a Copy activity: enter image description here Here my xml file and xsd file are in the same folder and as follow:
enter image description here

In the order.xml, use xsi:noNamespaceSchemaLocation="order.xsd" to specify the xsd file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>  
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
          xsi:noNamespaceSchemaLocation="order.xsd">  
          <orderItem>43546533</orderItem>
          <orderItem>53546533</orderItem>
          <orderItem>73546533</orderItem>
          <orderItem>93546533</orderItem>
          <orderItem>43546533</orderItem>
          <orderItem>73546533</orderItem>
          <orderItem>03546533</orderItem>
          <orderItem>33546533</orderItem>
          <orderItem>43216533</orderItem>
          <orderItem>1246533</orderItem>
          <orderItem>4466533</orderItem>
</order>  

order.xsd:

<?xml version="1.0" encoding="UTF-8"?>  
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"  
elementFormDefault="qualified" attributeFormDefault="qualified">  
    <xsd:element name="order">  
       <xsd:complexType>  
         <xsd:sequence>  
            <xsd:element name="orderItem" type="xsd:string"  maxOccurs="10"/>  
         </xsd:sequence>  
      </xsd:complexType>  
    </xsd:element>  
</xsd:schema> 

In my case, when the order.xml doesn't meet my verification rules, it will fails: enter image description here

Hope my answer is helpful to you!