Tej*_*ebb 1 xml xsd azure azure-data-factory
我正在尝试在 Azure 数据工厂复制活动中使用 XSD 验证(以 XML 作为源)。我有一个外部 XSD 文件。我还试图了解如何在 Azure 数据工厂中使用它。在复制活动中,验证类型部分下有两个选项 XSD 和 DTD。但是,它没有任何方法将任何外部文件指定为 XSD。文档对此也没有明确说明。(https://learn.microsoft.com/en-us/azure/data-factory/format-xml)。官方文档是这样说的:
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
Run Code Online (Sandbox Code Playgroud)
我对这里的第二点感到困惑。
“XML 必须在 XML 文件内引用”是什么意思?
我认为它说,我们应该在源 xml 文件中引用 XSD 文件(使用相对路径)。
例如:
在 ADF 中我设置了复制活动:
这里我的 xml 文件和 xsd 文件位于同一文件夹中,如下所示:

在order.xml中,用于xsi:noNamespaceSchemaLocation="order.xsd"指定xsd文件:
<?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>
Run Code Online (Sandbox Code Playgroud)
订单.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>
Run Code Online (Sandbox Code Playgroud)
就我而言,当 order.xml 不符合我的验证规则时,它将失败:

希望我的回答对您有帮助!