Logic App工作流Flat File Encode报错:指定命名空间无对应Schema
Logic App Flat File Encode报错:找不到指定目标命名空间的Schema
问题场景
在Logic App工作流中使用Flat File Encode步骤处理XML文件,已将XSD文件上传至Artifacts/Schema目录,但运行时触发报错:
"No schema has the specified target namespace http://B3.Schemas.Invoices"
尽管XSD中已明确指定目标命名空间,仍出现该错误。以下是当前使用的XSD Schema及测试XML文件:
现有XSD Schema
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:vs="http://B3.Schemas.Invoices" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://B3.Schemas.Invoices" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="Header"> <xs:complexType> <xs:sequence> <xs:element name="processSendTime" type="xs:string"/> <xs:element name="processTarget" type="xs:string"/> <xs:element name="processType" type="xs:string"/> <xs:element name="processDescription" type="xs:string"/> <xs:element name="processLogID" type="xs:string"/> <xs:element name="fileSequenceID" type="xs:string"/> <xs:element name="processSource" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
测试XML文件
<?xml version="1.0" encoding="utf-8"?> <vs:Invoices xmlns:vs="http://B3.Schemas.Invoices"> <Header> <processSendTime>2024-04-09T22:00:05</processSendTime> <processTarget></processTarget> <processType></processType> <processDescription></processDescription> <processLogID>90906422</processLogID> <fileSequenceID>85707</fileSequenceID> <processSource>Biblio3</processSource> </Header> </vs:Invoices>
问题原因分析
- 根元素不匹配:XSD中定义的根元素是
Header,但测试XML的根元素是Invoices,XSD未对该根元素进行定义,导致Flat File Encode无法匹配到对应Schema。 - 命名空间元素不符合要求:XSD中设置
elementFormDefault="qualified",意味着所有元素必须属于目标命名空间,但测试XML中的Header及其子元素未添加命名空间前缀vs:,不符合Schema的约束。
解决方案
步骤1:修改XSD Schema,添加根元素Invoices
更新后的XSD需要包含Invoices作为根元素,并引用Header元素:
<?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:vs="http://B3.Schemas.Invoices" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://B3.Schemas.Invoices" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <!-- 定义根元素Invoices --> <xs:element name="Invoices"> <xs:complexType> <xs:sequence> <!-- 引用Header元素 --> <xs:element ref="vs:Header"/> </xs:sequence> </xs:complexType> </xs:element> <!-- 原Header元素定义 --> <xs:element name="Header"> <xs:complexType> <xs:sequence> <xs:element name="processSendTime" type="xs:string"/> <xs:element name="processTarget" type="xs:string"/> <xs:element name="processType" type="xs:string"/> <xs:element name="processDescription" type="xs:string"/> <xs:element name="processLogID" type="xs:string"/> <xs:element name="fileSequenceID" type="xs:string"/> <xs:element name="processSource" type="xs:string"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
步骤2:修正测试XML的命名空间前缀
确保所有元素都添加vs:前缀,符合elementFormDefault="qualified"的要求:
<?xml version="1.0" encoding="utf-8"?> <vs:Invoices xmlns:vs="http://B3.Schemas.Invoices"> <vs:Header> <vs:processSendTime>2024-04-09T22:00:05</vs:processSendTime> <vs:processTarget></vs:processTarget> <vs:processType></vs:processType> <vs:processDescription></vs:processDescription> <vs:processLogID>90906422</vs:processLogID> <vs:fileSequenceID>85707</vs:fileSequenceID> <vs:processSource>Biblio3</vs:processSource> </vs:Header> </vs:Invoices>
步骤3:重新上传并测试
将修改后的XSD重新上传到Logic App的Artifacts/Schema目录,然后重新运行工作流测试。
内容的提问来源于stack exchange,提问作者Ian Smith
相关产品推荐
相关产品推荐

