BizTalk-将重复节点与输出与JSON数组的串联

发布于 2025-01-30 09:01:31 字数 7564 浏览 4 评论 0原文

我有以下类似于输入XML的东西。如您所见,节点MIF可以多次出现(一两次)。

<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>Not app</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties> 
            <ENT_SUB_TYP />
            <MIF_ACT_PER>3</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>6</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>3</MIF_ACT_PER>
            <MIF_ACT_PER>6</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>

相应的JSON输出文件应该看起来像以下内容:

{
  "Transactions": [
    {
      "Events": [
        {
          "Properties": [
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "NOT_APP"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "6"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3",
                "6"
              ]
            }
          ]
        }
      ]
    }
  ]
}

现在,我认为输出模式(仅显示有趣的部分)应该变成下面的类似,但我只是在猜测。我不知道常规的BizTalk JSON翻译器如何解释输出模式。

<Properties>
    <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
</Properties>
<Properties>    
    <MIF_ACT_PER>3</MIF_ACT_PER>
    <MIF_ACT_PER>6</MIF_ACT_PER>
</Properties>

我该如何在映射器中执行此操作?无论我如何尝试,我都无法弄清楚如何使用函数。而且我不了解XSLT,所以它也脱离了窗口(至少对我而言。非常感谢解决此问题的任何帮助!

更新: 这张图表示有故障的输出,它在其自身的属性节点中为我提供了“ 3”和“ 6”,而如前所述,我想将它们放入一个属性节点中。

更新2: 根据Dijkgraaf先生的建议,我正在更新该帖子。希望这次将足够清楚地了解我的问题以及我的困惑。

下面的四个示例输入是我在开发过程中使用的真实输入示例的排骨。数据已被掩盖。

<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>NOT_APP</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>3</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>6</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>3</MIF_ACT_PER>
        <MIF_ACT_PER>6</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>

现在,使用上述示例的映射输出和“ 4”和“ 6”给了我下面的内容:

<ns0:Masterdata xmlns:ns0="http://Masterdata">
    <Transactions>
        <EntityType>CRD</EntityType>
        <Events>            
            <Properties>
                <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
            </Properties>
            <Properties>
                <MIF_ACT_PER>3</MIF_ACT_PER>
            </Properties>
            <Properties>
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
</ns0:Masterdata>

映射完全与第一个更新中的图片所示。如果我使用最后一个包含“ 4”和“ 6”的示例文件(下面的JSON),则该映射给了我。

{
  "Transactions": [
    {
      "EntityType": "CRD",
      "Events": [
        {
          "Properties": [            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3"
              ]
            },
            {
              "MIF_ACT_PER": [
                "6"
              ]
            }
          ]
        }
      ]
    }
  ]
}

现在,关于映射中的源模式和目标架构,这就是我所做的。源模式是目标模式的蓝图。如您所见,映射中的目标架构确实包含一个选择节点。因此,这意味着将其中包含数据的节点(换句话说确实满足逻辑字符串函数素能要求)将发送到目标并输出XML。

关于源和目标模式,我真的希望我能与您分享。但是保密条款使我无法这样做。

我认为我也许可以创建一个虚拟模式,但是我不确定我是否能够实现您对真正模式的建议解决方案。除了目标模式中的选择节点外,其他方案实际上根本没有任何特别的内容。我真的希望这足够了。

我试图遵循Dijkgraafs先生的解决方案,以使目标模式尽可能简单,但实际上没有什么可以简化的。 (是的,我是第一个承认我远非专家的人,但我确实有几年的经验。)

当时该映射可以说什么?目标系统要求源模式中的每个属性作为属性节点的子节点来进行。展示它比解释更容易。请参阅下图。

我在循环函数方面做错了什么(这导致4和6在他们自己的属性节点中,而不是两个都以一个为单位)。

我还可以看出我的值映射函数看起来像这样:

最后,我希望这足够了,但是如果有人需要更多的投入,我会接受建议。而且,非常感谢您对我和我的不完整描述的耐心配合。

I have something like below as input xml. As you can see, the node MIF can come multiple times (one or two times).

<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>Not app</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties> 
            <ENT_SUB_TYP />
            <MIF_ACT_PER>3</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>6</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>
<Transactions>
    <Events>
        <Properties>
            <ENT_SUB_TYP />
            <MIF_ACT_PER>3</MIF_ACT_PER>
            <MIF_ACT_PER>6</MIF_ACT_PER>
        </Properties>
    </Events>
</Transactions>

The corresponding JSON output file is supposed to look something like below:

{
  "Transactions": [
    {
      "Events": [
        {
          "Properties": [
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "NOT_APP"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "6"
              ]
            }
          ]
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": [
            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3",
                "6"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Now, I do think that the output schema (showing only the interesting part) is supposed to become something like below but I am only guessing. I dont know how the regular BizTalk JSON translator interprets the output schema.

<Properties>
    <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
</Properties>
<Properties>    
    <MIF_ACT_PER>3</MIF_ACT_PER>
    <MIF_ACT_PER>6</MIF_ACT_PER>
</Properties>

How can I do this in the mapper? No matter how I try I just cant figure out how to use the functoids. And I dont understand XSLT so that goes out of the window as well (at least for me. If anyone understands how to, ie. use xslt and and the scripting functoid, that would be good as well). Any help to solve this issue is greatly appreciated!

Update:
This picture represents the faulty output which gives me the '3' and '6' in their own properties node whereas, as stated before, I would like to have them in in one properties node.
enter image description here

Update 2:
According to Mr. Dijkgraaf's suggestion I am updating the post. Hopefully this time it will be clear enough to understand my issue and also my confusion.

The four example input below are barebones of the real input examples I use during development. Data has been masked.

<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>NOT_APP</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>3</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>6</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>


<?xml version="1.0" encoding="utf-8"?>
<ns0:Masterdata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns0="http://Masterdata/">
  <EntityType xmlns="">CRD</EntityType>
  <Transactions xmlns="">
    <EntityType>CRD</EntityType>
    <Events>
      <Properties>
        <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
        <MIF_ACT_PER>3</MIF_ACT_PER>
        <MIF_ACT_PER>6</MIF_ACT_PER>
      </Properties>
    </Events>
  </Transactions>
</ns0:Masterdata>

Now, the output of the mapping using the above example with the '4' and '6' gives me below:

<ns0:Masterdata xmlns:ns0="http://Masterdata">
    <Transactions>
        <EntityType>CRD</EntityType>
        <Events>            
            <Properties>
                <ENT_SUB_TYP>NOT_APP</ENT_SUB_TYP>
            </Properties>
            <Properties>
                <MIF_ACT_PER>3</MIF_ACT_PER>
            </Properties>
            <Properties>
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
</ns0:Masterdata>

The mapping is exactly as the picture in the first update shows. And that mapping gives me, if I use the last example file that contains both the '4' and '6', the JSON below.

{
  "Transactions": [
    {
      "EntityType": "CRD",
      "Events": [
        {
          "Properties": [            
            {
              "ENT_SUB_TYP": [
                "NOT_APP"
              ]
            },
            {
              "MIF_ACT_PER": [
                "3"
              ]
            },
            {
              "MIF_ACT_PER": [
                "6"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Now, regarding the source schema and target schema in the mapping, this is what I did. The source schema worked as a blueprint for the target schema. As you can see, the target schema in the mapping does contain a choice node. So this means that nodes that have data in them (in other words do fulfill the logical string functoid requirement) will be sent to the target and output xml.

Regarding the source and target schema, I really wish that I could share them with you. But a confidentialty clause prevents me from doing that.

I think I could perhaps create a dummy schema but then I am not sure that I would actually be able to implement your suggested solution to the real schema. There really isn't anything particular at all with the schemas except for the choice node in the target schema. I really hope this will be enough.

I have tried to follow Mr. Dijkgraafs solution as to make the target schema as simple as possible but there really is nothing to simplify. (Yes, I am the first to admit that I am far from an expert but still, I do have a few years of experience.)

What can be said about the mapping then? The target system requires every property in the source schema to come as a child node of a properties node. It is easier to show it than to explain it. See picture below.

enter image description here

I am doing something wrong regarding the looping functoid (which results in the 4 and 6 coming in their own Properties node instead of them both coming in one).

I can also tell that my value mapping functoid looks like this:
enter image description here

Finally, I hope this will be enough but I am open to suggestions if anyone needs more input. And also, thanks a lot for your patience with me and my incomplete descriptions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2025-02-06 09:01:31

无需串联,您只需要正确定义模式即可,而JSON编码器将重复元素放入数组中。

首先,您的示例输入XML没有根节点,因此我将添加一个和名称空间,因为没有它,JSON Excoder不使用架构定义,而是给出了稍微不一致的结果。如果您的输入没有命名空间,则可以有一个模式来解析输入,而将其映射到的第二个模式确实具有名称空间,或者具有管道组件添加命名空间。

与此匹配的输入

<ns0:Transaction xmlns:ns0="https://SO72306470">
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>Not app</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties> 
                <ENT_SUB_TYP />
                <MIF_ACT_PER>3</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>3</MIF_ACT_PER>
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
</ns0:Transaction>

模式。

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.SO72306470_JSON" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.SO72306470_JSON" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Transactions">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Events">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Properties">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element minOccurs="0" maxOccurs="unbounded" name="ENT_SUB_TYP" type="xs:string" />
                    <xs:element minOccurs="0" maxOccurs="unbounded" name="MIF_ACT_PER" type="xs:string" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

然后,这是一张相当简单的地图,其中映射回到同一模式,您只需要一些逻辑即可设置ent_sub_type,当它为空时。

和一个带有JSON编码器的发送管道,然后将RemoveTeRenvelope设置为true

drop true通过文件,输出为。

{
  "Transactions": [
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "Not app"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "3"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "6"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "3",
              "6"
            ]
          }
        }
      ]
    }
  ]
}

No concatenation needed, you just need to define your schema correctly and the JSON Encoder will put the repeating elements into arrays.

First of all your sample input XML doesn't have a root node, so I'm going to add one as well as a namespace, as without it the JSON Encoder does not use the schema definition and instead gives slightly inconsistent results. If your input doesn't have a namespace, you can have one schema to parse the input, and a second schema that you map to that does have the namespace, or have a Pipeline component add the namespace.

Input

<ns0:Transaction xmlns:ns0="https://SO72306470">
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>Not app</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties> 
                <ENT_SUB_TYP />
                <MIF_ACT_PER>3</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
    <Transactions>
        <Events>
            <Properties>
                <ENT_SUB_TYP />
                <MIF_ACT_PER>3</MIF_ACT_PER>
                <MIF_ACT_PER>6</MIF_ACT_PER>
            </Properties>
        </Events>
    </Transactions>
</ns0:Transaction>

Schema that matches this.

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns="http://Scratch2.SO72306470_JSON" xmlns:b="http://schemas.microsoft.com/BizTalk/2003" targetNamespace="http://Scratch2.SO72306470_JSON" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Transactions">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="Events">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Properties">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element minOccurs="0" maxOccurs="unbounded" name="ENT_SUB_TYP" type="xs:string" />
                    <xs:element minOccurs="0" maxOccurs="unbounded" name="MIF_ACT_PER" type="xs:string" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Then it is a fairly simple map where map back to the same schema and you just need a bit of logic to set the ENT_SUB_TYPE when it is empty.

BizTalk Map

And a Send Pipeline with the JSON Encoder, and where you set the RemoveOuterEnvelope to True

Drop through the file and the output is.

{
  "Transactions": [
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "Not app"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "3"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "6"
            ]
          }
        }
      ]
    },
    {
      "Events": [
        {
          "Properties": {
            "ENT_SUB_TYP": [
              "NOT_APP"
            ],
            "MIF_ACT_PER": [
              "3",
              "6"
            ]
          }
        }
      ]
    }
  ]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文