Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何解析文件夹中的XML文件以映射字符串,列表<;字符串>;_Xml_Parsing_Dictionary_Groovy - Fatal编程技术网

如何解析文件夹中的XML文件以映射字符串,列表<;字符串>;

如何解析文件夹中的XML文件以映射字符串,列表<;字符串>;,xml,parsing,dictionary,groovy,Xml,Parsing,Dictionary,Groovy,我试图解析一个文件夹中的多个XML文件,并从每个文件中检索字符串、列表的映射。我在分离这些值时遇到了一个问题 //####XML文件结构示例 <fields> <fullName>DandbCompanyId</fullName> <trackFeedHistory>false</trackFeedHistory> <type>Lookup</type> </fields>

我试图解析一个文件夹中的多个XML文件,并从每个文件中检索字符串、列表的映射。我在分离这些值时遇到了一个问题

//####XML文件结构示例

 <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()