本文介绍了用于提取xml标记值并将其转换为CSV的perl代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我对Perl和编程非常陌生...请帮助我....
我有以下提到的XML:

Hi,
i m very new to perl and programming...pls help me....
i have an XML which is below mentioned:

<Body>
    <FreemanFees>
        <SdcLoanFacilityNumber>133752115</SdcLoanFacilityNumber>
        <DealId>34390939283</DealId>
        <Tranche>
            <SdcDealNumber>133753116</SdcDealNumber>
            <ManagerFeeAndCredits>
                <ManagerFeeAndCredit>
                    <FreemanFeesForManager scale="6" currencyId="500110" sdcCurrencyCode="US">0</FreemanFeesForManager>
                    <ManagerNumberForFreemanFee>8320</ManagerNumberForFreemanFee>
                </ManagerFeeAndCredit>
            </ManagerFeeAndCredits>
        </Tranche>
    </FreemanFees>
    <FreemanFees>
        <SdcLoanFacilityNumber>133754115</SdcLoanFacilityNumber>
        <DealId>34390939284</DealId>
        <Tranche>
            <SdcDealNumber>133755116</SdcDealNumber>
            <ManagerFeeAndCredits>
                <ManagerFeeAndCredit>
                    <FreemanFeesForManager scale="6" currencyId="500110" sdcCurrencyCode="US">0</FreemanFeesForManager>
                    <ManagerNumberForFreemanFee>9678</ManagerNumberForFreemanFee>
                </ManagerFeeAndCredit>
                <ManagerFeeAndCredit>
                    <FreemanFeesForManager scale="6" currencyId="500110" sdcCurrencyCode="US">0</FreemanFeesForManager>
                    <ManagerNumberForFreemanFee>5390</ManagerNumberForFreemanFee>
                </ManagerFeeAndCredit>
            </ManagerFeeAndCredits>
        </Tranche>
    </FreemanFees>
</Body>



我在方括号后面给了空格,否则它将被转换...
我的代码如下:



i have given space after brackets else it is getting converted...
and my code is as below:

#!/usr/bin/perl

# Script to illustrate how to parse a simple XML file
# and pick out all the values for a specific element, in
# this case all the titles.

# use strict;
use XML::Simple;
 se Data::Dumper;

# create object
$xml = new XML::Simple (KeyAttr=>[]);

# read XML file
$data = $xml->XMLin("fm.xml");


my $booklist = XMLin('fm.xml');    #booklist is the array 
# print Dumper($booklist);

foreach my $FreemanFees (@{$booklist->{FreemanFees}}) {

    print
    $FreemanFees->{SdcLoanFacilityNumber} , "," ,
    $FreemanFees->{DealId} ,",",
    $FreemanFees->{Tranche}->{SdcDealNumber} , "," ,
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{ManagerNumberForFreemanFee}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{currencyId},",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{sdcCurrencyCode} , "," ,
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{scale}, ",",
    $FreemanFees->{Tranche}->{ManagerFeeAndCredits}->{ManagerFeeAndCredit}->{FreemanFeesForManager}->{content} , "," ,"\n";
    }




我的程序输出如下:
133752115,34390939283,133753116,,500110,US,6,0,
133754115,34390939284,133755116 ,,,,,


问题是我无法获取在同一节点中重复的所有标签值....有人可以在这方面帮助我还是可以指导我...

问候
Amar




my output of my program is as follows:
133752115,34390939283,133753116,,500110,US,6,0,
133754115,34390939284,133755116,,,,,,


problem is i m not able to fetch all the tag values which are repeating in the same node....can anyone help me in this aspect or guide me...

Regards
Amar

推荐答案




这篇关于用于提取xml标记值并将其转换为CSV的perl代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:43