如何解析文件夹中的XML文件以映射字符串,列表<;字符串>;
我试图解析一个文件夹中的多个XML文件,并从每个文件中检索字符串、列表的映射。我在分离这些值时遇到了一个问题 //####XML文件结构示例如何解析文件夹中的XML文件以映射字符串,列表<;字符串>;,xml,parsing,dictionary,groovy,Xml,Parsing,Dictionary,Groovy,我试图解析一个文件夹中的多个XML文件,并从每个文件中检索字符串、列表的映射。我在分离这些值时遇到了一个问题 //####XML文件结构示例 <fields> <fullName>DandbCompanyId</fullName> <trackFeedHistory>false</trackFeedHistory> <type>Lookup</type> </fields>
<fields>
<fullName>DandbCompanyId</fullName>
<trackFeedHistory>false</trackFeedHistory>
<type>Lookup</type>
</fields>
<fields>
<fullName>Description</fullName>
<trackFeedHistory>false</trackFeedHistory>
</fields>
<fields>
<fullName>DunsNumber</fullName>
<trackFeedHistory>false</trackFeedHistory>
</fields>
<fields>
<fullName>Fax</fullName>
<trackFeedHistory>false</trackFeedHistory>
</fields>
<fields>
<fullName>Industry</fullName>
<trackFeedHistory>false</trackFeedHistory>
<type>Picklist</type>
</fields>
<fields>
<fullName>IsCustomerPortal</fullName>
</fields>
<fields>
<fullName>IsPartner</fullName>
<trackFeedHistory>false</trackFeedHistory>
</fields>
<listViews>
<fullName>AllAccounts</fullName>
<filterScope>Everything</filterScope>
<label>All Accounts</label>
</listViews>
<listViews>
<fullName>MyAccounts</fullName>
<filterScope>Mine</filterScope>
<label>My Accounts</label>
</listViews>
//这是输出
DescriptionIsAlohaSupportedIsLightningSupportedNameOwnerIdStartingContext
IndustryOwnership
AllocationIdAmountBudgetIdChannelPartnerIdDescriptionOwnerIdRequestIdStatusTitle
ScorecardIdTargetEntityId
ActivityAllocationIdAmountBudgetIdCampaignIdChannelPartnerIdDescriptionDesiredOutcomeOwnerIdRequestedAmountStatusTitleTotalApprovedFcsTotalReimbursedFcs
CategoriesStatus
CapturedAngleContentDocumentIdImageAlternateTextImageClassImageClassObjectTypeImageTitleImageUrlImageViewTypeIsActiveName
Role
我的目标是实现以下目标:
位置ID、金额、预算TID、频道
因此,它应该看起来像一个字符串列表(在映射中它将是值)您尝试的内容有两个问题 第一种方法是使用
each
,它对集合中的每个项执行操作,但返回原始集合(不是操作的结果——为此,您需要collect
)
第二个是它。@fullName
将返回标记上的属性fullName
(即:如果您有…
),而您只需要节点的文本()
因此,以下方法可能会奏效:
xs.parse(file).fields.fullName.collect { it.text() }
但在Groovy中,我们可以缩短此collect
以使用扩展运算符*
,这将缩短:
xs.parse(file).fields.fullName*.text()
玩得开心 能否尝试将xs.parse(file).fields.fullName.each{it@fullName}
更改为xs.parse(file.fields.fullName*.text()
谢谢!!!!终于成功了,我在过去的两天里尝试了所有我能找到的东西!我在下面添加了一个解释作为答案
xs.parse(file).fields.fullName*.text()