循环xml,检索节点值,并使用Xquery构造xml输出



团队,我需要你们的帮助/专业知识来通过遍历xml响应来检索节点值。我想把它用作集成中间件。

输入文件示例:

<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices"
xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
xml:base="https://api12preview.sapsf.eu:443/odata/v2/">
<title type="text">PerEmail</title>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail</id>
<updated>2022-11-09T13:58:27Z</updated>
<link href="PerEmail" rel="self" title="PerEmail"/>
<entry>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail(emailType='54139',personIdExternal='GI00152188')</id>
<title type="text"/>
<updated>2022-11-09T13:58:27Z</updated>
<author>
<name/>
</author>
<link href="PerEmail(emailType='54139',personIdExternal='GI00152188')"
rel="edit"
title="PerEmail"/>
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="SFOData.PerEmail"/>
<content type="application/xml">
<  properties>
<d:personIdExternal>GI00152188</d:personIdExternal>
<d:emailAddress>someone@test_boehringer.com</d:emailAddress>
</m:properties>
</content>
</entry>
<entry>
<id>https://api12preview.sapsf.eu:443/odata/v2/PerEmail(emailType='54139',personIdExternal='GI00453224')</id>
<title type="text"/>
<updated>2022-11-09T13:58:27Z</updated>
<author>
<name/>
</author>
<link href="PerEmail(emailType='54139',personIdExternal='GI00453224')"
rel="edit"
title="PerEmail"/>
<category scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"
term="SFOData.PerEmail"/>
<content type="application/xml">
<m:properties>
<d:personIdExternal>GI00453224</d:personIdExternal>
<d:emailAddress>someone@test_boehringer.com</d:emailAddress>
</m:properties>
</content>
</entry>
<link href="https://api12preview.sapsf.eu:443/odata/v2/PerEmail?$select=emailAddress,personIdExternal&amp;$filter=emailType%20eq%2054139&amp;$skiptoken=eyJzdGFydFJvdyI6MTAwMCwiZW5kUm93IjoyMDAwfQ=="
rel="next"/>
</feed>

在此响应或xml Xquery应该运行所有'entry'节点并选择节点' personideexternal '的值,我期待这样的结果

<element>
<personIdExternal>GI00152188</personIdExternal>
<personIdExternal>GI00453224</personIdExternal>
</element>

我之前尝试过下面的代码,但它在这里不起作用,我怀疑这是由于源xml中的命名空间。我的知识是有限的XQuery -请帮助

{let $input:= /entry
for $i in $input/properties
return 
<element>
<personIdExternal>{i/personIdExternal/text()}</personIdExternal>
</element>}

/entry没有选择任何东西,因为entry元素不在顶层,它们在一个命名空间中。

$input/properties是错误的,因为属性元素不是entry的子元素,它在一个命名空间。

i没有选择任何东西,应该是$i

personIdExternal不选择任何东西,因为它在一个命名空间中。

你只需要

<element>{//*:personIdExternal}</element>

最新更新