简体   繁体   中英

XML validation in Azure Data Factory

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"?

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: 在此处输入图片说明 Here my xml file and xsd file are in the same folder and as follow:
在此处输入图片说明

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: 在此处输入图片说明

Hope my answer is helpful to you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM