如何准确地从XML文件获取子节点和该节点中的数据

时间:2022-10-31 11:20:38

My XML file

我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<group 
       xmlns='http://www.xbrl.org/2001/instance'
       xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
       xmlns:iso4217='http://www.xbrlSolutions.com/taxonomies/iso4217/2002-06-30'
       xmlns:iascf-pfs='http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15'
       xmlns:novartis='http://www.xbrl.org/taxonomy/int/fr/ias/pfs/2002-11-15/Novartis-2002-11-15'
       xsi:schemaLocation='
                 http://www.xbrlSolutions.com/taxonomies/iso4217/2002-06-30 http://www.xbrlSolutions.com/taxonomies/iso4217/2002-06-30/iso4217.xsd 
                 http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15 ias-ci-pfs-2002-11-15-WINDOW.xsd 
                 http://www.xbrl.org/taxonomy/int/fr/ias/pfs/2002-11-15/Novartis-2002-11-15 Novartis-2002-11-15.xsd 
       '>
      <iascf-pfs:RevenueFunction numericContext='Group2001ForPeriod'>32038000000</iascf-pfs:RevenueFunction>
      <iascf-pfs:RevenueFunction numericContext='Group2000ForPeriod'>35805000000</iascf-pfs:RevenueFunction>
      <iascf-pfs:CostSalesFunction numericContext='Group2001ForPeriod'>7886000000</iascf-pfs:CostSalesFunction>
      <iascf-pfs:CostSalesFunction numericContext='Group2000ForPeriod'>10242000000</iascf-pfs:CostSalesFunction>
      <iascf-pfs:GrossProfitFunction numericContext='Group2001ForPeriod'>24152000000</iascf-pfs:GrossProfitFunction>
      <iascf-pfs:GrossProfitFunction numericContext='Group2000ForPeriod'>25563000000</iascf-pfs:GrossProfitFunction>
      <iascf-pfs:MarketingDistributionCostsFunction numericContext='Group2001ForPeriod'>11098000000</iascf-pfs:MarketingDistributionCostsFunction>
      <iascf-pfs:MarketingDistributionCostsFunction numericContext='Group2000ForPeriod'>10945000000</iascf-pfs:MarketingDistributionCostsFunction>
      <iascf-pfs:ResearchDevelopmentFunction numericContext='Group2001ForPeriod'>4189000000</iascf-pfs:ResearchDevelopmentFunction>
      <iascf-pfs:ResearchDevelopmentFunction numericContext='Group2000ForPeriod'>4657000000</iascf-pfs:ResearchDevelopmentFunction>
      <iascf-pfs:AdministrativeExpensesFunction numericContext='Group2001ForPeriod'>1588000000</iascf-pfs:AdministrativeExpensesFunction>
      <iascf-pfs:AdministrativeExpensesFunction numericContext='Group2000ForPeriod'>2078000000</iascf-pfs:AdministrativeExpensesFunction>
      <iascf-pfs:ProfitLossOperationsFunction numericContext='Group2001ForPeriod'>7277000000</iascf-pfs:ProfitLossOperationsFunction>
      <iascf-pfs:ProfitLossOperationsFunction numericContext='Group2000ForPeriod'>7883000000</iascf-pfs:ProfitLossOperationsFunction>
      <iascf-pfs:ShareProfitLossEquityAccountedInvestments numericContext='Group2001ForPeriod'>139000000</iascf-pfs:ShareProfitLossEquityAccountedInvestments>
      <iascf-pfs:ShareProfitLossEquityAccountedInvestments numericContext='Group2000ForPeriod'>98000000</iascf-pfs:ShareProfitLossEquityAccountedInvestments>
      <iascf-pfs:FinanceCosts numericContext='Group2001ForPeriod'>-1067000000</iascf-pfs:FinanceCosts>
      <iascf-pfs:FinanceCosts numericContext='Group2000ForPeriod'>-1091000000</iascf-pfs:FinanceCosts>
      <iascf-pfs:ProfitLossBeforeTax numericContext='Group2001ForPeriod'>8483000000</iascf-pfs:ProfitLossBeforeTax>
      <iascf-pfs:ProfitLossBeforeTax numericContext='Group2000ForPeriod'>9072000000</iascf-pfs:ProfitLossBeforeTax>
      <iascf-pfs:IncomeTaxExpenseIncome numericContext='Group2001ForPeriod'>1440000000</iascf-pfs:IncomeTaxExpenseIncome>
      <iascf-pfs:IncomeTaxExpenseIncome numericContext='Group2000ForPeriod'>1820000000</iascf-pfs:IncomeTaxExpenseIncome>
      <iascf-pfs:ProfitLossAfterTax numericContext='Group2001ForPeriod'>7043000000</iascf-pfs:ProfitLossAfterTax>
      <iascf-pfs:BasicEarningsLossPerShare numericContext='Group2000ForPeriod'>2.75</iascf-pfs:BasicEarningsLossPerShare>
      <iascf-pfs:DilutedEarningsLossPerShare numericContext='Group2001ForPeriod'>2.72</iascf-pfs:DilutedEarningsLossPerShare>
      <iascf-pfs:DilutedEarningsLossPerShare numericContext='Group2000ForPeriod'>2.75</iascf-pfs:DilutedEarningsLossPerShare>
      <iascf-pfs:PropertyPlantEquipment numericContext='Group2001AsOf'>9060000000</iascf-pfs:PropertyPlantEquipment>
      <iascf-pfs:PropertyPlantEquipment numericContext='Group2000AsOf'>9030000000</iascf-pfs:PropertyPlantEquipment>
      <iascf-pfs:IntangibleAssets numericContext='Group2001AsOf'>6548000000</iascf-pfs:IntangibleAssets>
      <iascf-pfs:IntangibleAssets numericContext='Group2000AsOf'>5830000000</iascf-pfs:IntangibleAssets>
      <iascf-pfs:InvestmentsAssociates numericContext='Group2001AsOf'>6715000000</iascf-pfs:InvestmentsAssociates>
      <iascf-pfs:InvestmentsAssociates numericContext='Group2000AsOf'>1531000000</iascf-pfs:InvestmentsAssociates>
      <iascf-pfs:DeferredTaxAssets numericContext='Group2001AsOf'>3235000000</iascf-pfs:DeferredTaxAssets>
      <iascf-pfs:DeferredTaxAssets numericContext='Group2000AsOf'>3265000000</iascf-pfs:DeferredTaxAssets>
      <iascf-pfs:OtherFinancialAssetsNonCurrent numericContext='Group2001AsOf'>7027000000</iascf-pfs:OtherFinancialAssetsNonCurrent>
      <iascf-pfs:OtherFinancialAssetsNonCurrent numericContext='Group2000AsOf'>5601000000</iascf-pfs:OtherFinancialAssetsNonCurrent>
      <iascf-pfs:NonCurrentAssets numericContext='Group2001AsOf'>32585000000</iascf-pfs:NonCurrentAssets>
      <iascf-pfs:NonCurrentAssets numericContext='Group2000AsOf'>25257000000</iascf-pfs:NonCurrentAssets>
      <iascf-pfs:Inventories numericContext='Group2001AsOf'>4112000000</iascf-pfs:Inventories>
      <iascf-pfs:Inventories numericContext='Group2000AsOf'>4122000000</iascf-pfs:Inventories>
      <iascf-pfs:TradeOtherReceivablesCurrent numericContext='Group2001AsOf'>5349000000</iascf-pfs:TradeOtherReceivablesCurrent>
      <iascf-pfs:TradeOtherReceivablesCurrent numericContext='Group2000AsOf'>5283000000</iascf-pfs:TradeOtherReceivablesCurrent>
      <iascf-pfs:OtherAssetsCurrent numericContext='Group2001AsOf'>2895000000</iascf-pfs:OtherAssetsCurrent>
      <iascf-pfs:OtherAssetsCurrent numericContext='Group2000AsOf'>3011000000</iascf-pfs:OtherAssetsCurrent>
      <iascf-pfs:AvailableSaleInvestmentsCurrent numericContext='Group2001AsOf'>10697000000</iascf-pfs:AvailableSaleInvestmentsCurrent>
      <iascf-pfs:AvailableSaleInvestmentsCurrent numericContext='Group2000AsOf'>11720000000</iascf-pfs:AvailableSaleInvestmentsCurrent>
      <iascf-pfs:CashCashEquivalents numericContext='Group2001AsOf'>11147000000</iascf-pfs:CashCashEquivalents>
      <iascf-pfs:CashCashEquivalents numericContext='Group2000AsOf'>8803000000</iascf-pfs:CashCashEquivalents>
      <iascf-pfs:CurrentAssets numericContext='Group2001AsOf'>34200000000</iascf-pfs:CurrentAssets>
      <iascf-pfs:CurrentAssets numericContext='Group2000AsOf'>32939000000</iascf-pfs:CurrentAssets>
      <iascf-pfs:Assets numericContext='Group2001AsOf'>66785000000</iascf-pfs:Assets>
      <iascf-pfs:Assets numericContext='Group2000AsOf'>58196000000</iascf-pfs:Assets>
      <iascf-pfs:IssuedCapital numericContext='Group2001AsOf'>1443000000</iascf-pfs:IssuedCapital>
      <iascf-pfs:IssuedCapital numericContext='Group2000AsOf'>1443000000</iascf-pfs:IssuedCapital>
      <iascf-pfs:TreasuryShares numericContext='Group2001AsOf'>169000000</iascf-pfs:TreasuryShares>
      <iascf-pfs:TreasuryShares numericContext='Group2000AsOf'>139000000</iascf-pfs:TreasuryShares>
      <iascf-pfs:Reserves numericContext='Group2001AsOf'>40971000000</iascf-pfs:Reserves>
      <iascf-pfs:Reserves numericContext='Group2000AsOf'>35558000000</iascf-pfs:Reserves>
      <iascf-pfs:Equity numericContext='Group2001AsOf'>42245000000</iascf-pfs:Equity>
      <iascf-pfs:Equity numericContext='Group2000AsOf'>36862000000</iascf-pfs:Equity>
      <iascf-pfs:MinorityInterestsNetAssets numericContext='Group2001AsOf'>104000000</iascf-pfs:MinorityInterestsNetAssets>
      <iascf-pfs:MinorityInterestsNetAssets numericContext='Group2000AsOf'>78000000</iascf-pfs:MinorityInterestsNetAssets>
      <iascf-pfs:InterestBearingBorrowingsNonCurrent numericContext='Group2001AsOf'>2492000000</iascf-pfs:InterestBearingBorrowingsNonCurrent>
      <iascf-pfs:InterestBearingBorrowingsNonCurrent numericContext='Group2000AsOf'>2283000000</iascf-pfs:InterestBearingBorrowingsNonCurrent>
      <iascf-pfs:DeferredTaxLiabilities numericContext='Group2001AsOf'>3885000000</iascf-pfs:DeferredTaxLiabilities>
      <iascf-pfs:DeferredTaxLiabilities numericContext='Group2000AsOf'>3488000000</iascf-pfs:DeferredTaxLiabilities>
      <iascf-pfs:OtherLiabilitiesNonCurrent numericContext='Group2001AsOf'>3830000000</iascf-pfs:OtherLiabilitiesNonCurrent>
      <iascf-pfs:OtherLiabilitiesNonCurrent numericContext='Group2000AsOf'>3845000000</iascf-pfs:OtherLiabilitiesNonCurrent>
      <iascf-pfs:NonCurrentLiabilities numericContext='Group2001AsOf'>10207000000</iascf-pfs:NonCurrentLiabilities>
      <iascf-pfs:NonCurrentLiabilities numericContext='Group2000AsOf'>9616000000</iascf-pfs:NonCurrentLiabilities>
      <iascf-pfs:TradeOtherPayablesCurrent numericContext='Group2001AsOf'>1809000000</iascf-pfs:TradeOtherPayablesCurrent>
      <iascf-pfs:TradeOtherPayablesCurrent numericContext='Group2000AsOf'>1591000000</iascf-pfs:TradeOtherPayablesCurrent>
      <iascf-pfs:InterestBearingBorrowingsCurrent numericContext='Group2001AsOf'>5074000000</iascf-pfs:InterestBearingBorrowingsCurrent>
      <iascf-pfs:InterestBearingBorrowingsCurrent numericContext='Group2000AsOf'>3779000000</iascf-pfs:InterestBearingBorrowingsCurrent>
      <iascf-pfs:OtherLiabilitiesCurrent numericContext='Group2001AsOf'>7346000000</iascf-pfs:OtherLiabilitiesCurrent>
      <iascf-pfs:OtherLiabilitiesCurrent numericContext='Group2000AsOf'>6270000000</iascf-pfs:OtherLiabilitiesCurrent>
      <iascf-pfs:CurrentLiabilities numericContext='Group2001AsOf'>14229000000</iascf-pfs:CurrentLiabilities>
      <iascf-pfs:CurrentLiabilities numericContext='Group2000AsOf'>11640000000</iascf-pfs:CurrentLiabilities>
      <iascf-pfs:Liabilities numericContext='Group2001AsOf'>24436000000</iascf-pfs:Liabilities>
      <iascf-pfs:Liabilities numericContext='Group2000AsOf'>21256000000</iascf-pfs:Liabilities>
      <iascf-pfs:LiabilitiesEquity numericContext='Group2001AsOf'>66785000000</iascf-pfs:LiabilitiesEquity>
      <iascf-pfs:LiabilitiesEquity numericContext='Group2000AsOf'>58196000000</iascf-pfs:LiabilitiesEquity>
      <iascf-pfs:CashFlowsBeforeChangesWorkingCapitalProfitLossOperationsNetProfitLossTransferredToEquity numericContext='Group2001ForPeriod'>7024000000</iascf-pfs:CashFlowsBeforeChangesWorkingCapitalProfitLossOperationsNetProfitLossTransferredToEquity>
      <iascf-pfs:CashFlowsBeforeChangesWorkingCapitalProfitLossOperationsNetProfitLossTransferredToEquity numericContext='Group2000ForPeriod'>7210000000</iascf-pfs:CashFlowsBeforeChangesWorkingCapitalProfitLossOperationsNetProfitLossTransferredToEquity>
      <iascf-pfs:AdjustmentsReconcileProfitLossOperationsMinorityInterestsIncludedGroupProfitLoss numericContext='Group2001ForPeriod'>19000000</iascf-pfs:AdjustmentsReconcileProfitLossOperationsMinorityInterestsIncludedGroupProfitLoss>
      <iascf-pfs:AdjustmentsReconcileProfitLossOperationsMinorityInterestsIncludedGroupProfitLoss numericContext='Group2000ForPeriod'>42000000</iascf-pfs:AdjustmentsReconcileProfitLossOperationsMinorityInterestsIncludedGroupProfitLoss>
      <iascf-pfs:IncomeTaxExpenseIncomeRelatingCashFlowsOperatingActivities numericContext='Group2001ForPeriod'>1440000000</iascf-pfs:IncomeTaxExpenseIncomeRelatingCashFlowsOperatingActivities>
      <iascf-pfs:IncomeTaxExpenseIncomeRelatingCashFlowsOperatingActivities numericContext='Group2000ForPeriod'>1820000000</iascf-pfs:IncomeTaxExpenseIncomeRelatingCashFlowsOperatingActivities>
      <iascf-pfs:DepreciationRelatingCashFlowsOperatingActivities numericContext='Group2001ForPeriod'>969000000</iascf-pfs:DepreciationRelatingCashFlowsOperatingActivities>
      <iascf-pfs:DepreciationRelatingCashFlowsOperatingActivities numericContext='Group2000ForPeriod'>1196000000</iascf-pfs:DepreciationRelatingCashFlowsOperatingActivities>
      <iascf-pfs:AmortisationRelatingCashFlowsOperatingActivities numericContext='Group2001ForPeriod'>780000000</iascf-pfs:AmortisationRelatingCashFlowsOperatingActivities>
      <iascf-pfs:AmortisationRelatingCashFlowsOperatingActivities numericContext='Group2000ForPeriod'>309000000</iascf-pfs:AmortisationRelatingCashFlowsOperatingActivities>
      <iascf-pfs:ImpairmentChargeReversalRelatingCashFlowsOperatingActivities numericContext='Group2001ForPeriod'>31000000</iascf-pfs:ImpairmentChargeReversalRelatingCashFlowsOperatingActivities>
      <iascf-pfs:ImpairmentChargeReversalRelatingCashFlowsOperatingActivities numericContext='Group2000ForPeriod'>0</iascf-pfs:ImpairmentChargeReversalRelatingCashFlowsOperatingActivities>
      <iascf-pfs:AdjustmentsReconcileProfitLossOperationsShareProfitLossEquityAccountedInvestments numericContext='Group2001ForPeriod'>139000000</iascf-pfs:AdjustmentsReconcileProfitLossOperationsShareProfitLossEquityAccountedInvestments>
      <iascf-pfs:AdjustmentsReconcileProfitLossOperationsShareProfitLossEquityAccountedInvestments numericContext='Group2000ForPeriod'>98000000</iascf-pfs:AdjustmentsReconcileProfitLossOperationsShareProfitLossEquityAccountedInvestments>
      <novartis:GainsOnDisposalTangibleIntangibleAssets numericContext='Group2001ForPeriod'>510000000</novartis:GainsOnDisposalTangibleIntangibleAssets>
      <novartis:GainsOnDisposalTangibleIntangibleAssets numericContext='Group2000ForPeriod'>1000000</novartis:GainsOnDisposalTangibleIntangibleAssets>
      <novartis:NetFinancialIncome numericContext='Group2001ForPeriod'>1067000000</novartis:NetFinancialIncome>
      <novartis:NetFinancialIncome numericContext='Group2000ForPeriod'>1091000000</novartis:NetFinancialIncome>
      <iascf-pfs:InterestReceivedClassifiedOperating numericContext='Group2001ForPeriod'>779000000</iascf-pfs:InterestReceivedClassifiedOperating>
      <iascf-pfs:InterestReceivedClassifiedOperating numericContext='Group2000ForPeriod'>1944000000</iascf-pfs:InterestReceivedClassifiedOperating>
      <iascf-pfs:InterestPaidClassifiedOperating numericContext='Group2001ForPeriod'>391000000</iascf-pfs:InterestPaidClassifiedOperating>
      <iascf-pfs:InterestPaidClassifiedOperating numericContext='Group2000ForPeriod'>1211000000</iascf-pfs:InterestPaidClassifiedOperating>
      <iascf-pfs:IncomeTaxesPaid numericContext='Group2001ForPeriod'>1377000000</iascf-pfs:IncomeTaxesPaid>
      <iascf-pfs:IncomeTaxesPaid numericContext='Group2000ForPeriod'>2176000000</iascf-pfs:IncomeTaxesPaid>
      <novartis:CashFlowBeforeWorkingCapitalProvisionsChanges numericContext='Group2001ForPeriod'>7558000000</novartis:CashFlowBeforeWorkingCapitalProvisionsChanges>
      <novartis:CashFlowBeforeWorkingCapitalProvisionsChanges numericContext='Group2000ForPeriod'>7944000000</novartis:CashFlowBeforeWorkingCapitalProvisionsChanges>
      <iascf-pfs:IncreaseDecreaseProvisionsRelatingCashFlowsOperatingActivities numericContext='Group2001ForPeriod'>421000000</iascf-pfs:IncreaseDecreaseProvisionsRelatingCashFlowsOperatingActivities>
      <iascf-pfs:IncreaseDecreaseProvisionsRelatingCashFlowsOperatingActivities numericContext='Group2000ForPeriod'>439000000</iascf-pfs:IncreaseDecreaseProvisionsRelatingCashFlowsOperatingActivities>
      <iascf-pfs:IncreaseDecreaseWorkingCapital numericContext='Group2001ForPeriod'>205000000</iascf-pfs:IncreaseDecreaseWorkingCapital>
      <iascf-pfs:IncreaseDecreaseWorkingCapital numericContext='Group2000ForPeriod'>107000000</iascf-pfs:IncreaseDecreaseWorkingCapital>
      <iascf-pfs:CashFlowsUsedOperationsIndirectMethod numericContext='Group2001ForPeriod'>7342000000</iascf-pfs:CashFlowsUsedOperationsIndirectMethod>
      <iascf-pfs:CashFlowsUsedOperationsIndirectMethod numericContext='Group2000ForPeriod'>7612000000</iascf-pfs:CashFlowsUsedOperationsIndirectMethod>
      <iascf-pfs:PaymentsAcquirePropertyPlantEquipment numericContext='Group2001ForPeriod'>1351000000</iascf-pfs:PaymentsAcquirePropertyPlantEquipment>
      <iascf-pfs:PaymentsAcquirePropertyPlantEquipment numericContext='Group2000ForPeriod'>1353000000</iascf-pfs:PaymentsAcquirePropertyPlantEquipment>
      <iascf-pfs:ProceedsDisposalPropertyPlantEquipment numericContext='Group2001ForPeriod'>275000000</iascf-pfs:ProceedsDisposalPropertyPlantEquipment>
      <iascf-pfs:ProceedsDisposalPropertyPlantEquipment numericContext='Group2000ForPeriod'>347000000</iascf-pfs:ProceedsDisposalPropertyPlantEquipment>
      <novartis:PurchaseIntangibleFinancialAssets numericContext='Group2001ForPeriod'>7552000000</novartis:PurchaseIntangibleFinancialAssets>
      <novartis:PurchaseIntangibleFinancialAssets numericContext='Group2000ForPeriod'>3149000000</novartis:PurchaseIntangibleFinancialAssets>
      <novartis:ProceedsFromDisposalsIntangibleFinancialAssets numericContext='Group2001ForPeriod'>1550000000</novartis:ProceedsFromDisposalsIntangibleFinancialAssets>
      <novartis:ProceedsFromDisposalsIntangibleFinancialAssets numericContext='Group2000ForPeriod'>471000000</novartis:ProceedsFromDisposalsIntangibleFinancialAssets>
      <iascf-pfs:PaymentsAcquireSubsidiariesNetCashAcquired numericContext='Group2001ForPeriod'>169000000</iascf-pfs:PaymentsAcquireSubsidiariesNetCashAcquired>
      <iascf-pfs:PaymentsAcquireSubsidiariesNetCashAcquired numericContext='Group2000ForPeriod'>1371000000</iascf-pfs:PaymentsAcquireSubsidiariesNetCashAcquired>
      <iascf-pfs:PaymentsAcquireOtherAssets numericContext='Group2001ForPeriod'>1000000</iascf-pfs:PaymentsAcquireOtherAssets>
      <iascf-pfs:PaymentsAcquireOtherAssets numericContext='Group2000ForPeriod'>0</iascf-pfs:PaymentsAcquireOtherAssets>
      <iascf-pfs:ProceedsDisposalOtherFinancialAssets numericContext='Group2001ForPeriod'>2573000000</iascf-pfs:ProceedsDisposalOtherFinancialAssets>
      <iascf-pfs:ProceedsDisposalOtherFinancialAssets numericContext='Group2000ForPeriod'>4839000000</iascf-pfs:ProceedsDisposalOtherFinancialAssets>
      <iascf-pfs:NetCashFlowsUsedInvestingActivities numericContext='Group2001ForPeriod'>-4675000000</iascf-pfs:NetCashFlowsUsedInvestingActivities>
      <iascf-pfs:NetCashFlowsUsedInvestingActivities numericContext='Group2000ForPeriod'>-216000000</iascf-pfs:NetCashFlowsUsedInvestingActivities>
      <iascf-pfs:PurchaseTreasuryShares numericContext='Group2001ForPeriod'>3848000000</iascf-pfs:PurchaseTreasuryShares>
      <iascf-pfs:PurchaseTreasuryShares numericContext='Group2000ForPeriod'>1165000000</iascf-pfs:PurchaseTreasuryShares>
      <iascf-pfs:ProceedsIssueEquityInstruments numericContext='Group2001ForPeriod'>4056000000</iascf-pfs:ProceedsIssueEquityInstruments>
      <iascf-pfs:ProceedsIssueEquityInstruments numericContext='Group2000ForPeriod'>0</iascf-pfs:ProceedsIssueEquityInstruments>
      <novartis:ChangeInLongTermFinancialDebts numericContext='Group2001ForPeriod'>1258000000</novartis:ChangeInLongTermFinancialDebts>
      <novartis:ChangeInLongTermFinancialDebts numericContext='Group2000ForPeriod'>-124000000</novartis:ChangeInLongTermFinancialDebts>
      <novartis:ChangeInShortTermFinancialDebts numericContext='Group2001ForPeriod'>374000000</novartis:ChangeInShortTermFinancialDebts>
      <novartis:ChangeInShortTermFinancialDebts numericContext='Group2000ForPeriod'>-1402000000</novartis:ChangeInShortTermFinancialDebts>
      <iascf-pfs:DividendsPaidClassifiedFinancing numericContext='Group2001ForPeriod'>2194000000</iascf-pfs:DividendsPaidClassifiedFinancing>
      <iascf-pfs:DividendsPaidClassifiedFinancing numericContext='Group2000ForPeriod'>2064000000</iascf-pfs:DividendsPaidClassifiedFinancing>
      <iascf-pfs:NetCashFlowsUsedFinancingActivities numericContext='Group2001ForPeriod'>-354000000</iascf-pfs:NetCashFlowsUsedFinancingActivities>
      <iascf-pfs:NetCashFlowsUsedFinancingActivities numericContext='Group2000ForPeriod'>-4755000000</iascf-pfs:NetCashFlowsUsedFinancingActivities>
      <iascf-pfs:EffectExchangeRateChangesCashCashEquivalents numericContext='Group2001ForPeriod'>31000000</iascf-pfs:EffectExchangeRateChangesCashCashEquivalents>
      <iascf-pfs:EffectExchangeRateChangesCashCashEquivalents numericContext='Group2000ForPeriod'>-119000000</iascf-pfs:EffectExchangeRateChangesCashCashEquivalents>
      <iascf-pfs:NetIncreaseDecreaseCashCashEquivalents numericContext='Group2001ForPeriod'>2344000000</iascf-pfs:NetIncreaseDecreaseCashCashEquivalents>
      <iascf-pfs:NetIncreaseDecreaseCashCashEquivalents numericContext='Group2000ForPeriod'>2522000000</iascf-pfs:NetIncreaseDecreaseCashCashEquivalents>
      <iascf-pfs:CashCashEquivalentsBeginningBalance numericContext='Group2000AsOf'>8803000000</iascf-pfs:CashCashEquivalentsBeginningBalance>
      <iascf-pfs:CashCashEquivalentsBeginningBalance numericContext='Group1999AsOf'>6281000000</iascf-pfs:CashCashEquivalentsBeginningBalance>
      <iascf-pfs:CashCashEquivalentsEndingBalance numericContext='Group2001AsOf'>11147000000</iascf-pfs:CashCashEquivalentsEndingBalance>
      <iascf-pfs:CashCashEquivalentsEndingBalance numericContext='Group2000AsOf'>8803000000</iascf-pfs:CashCashEquivalentsEndingBalance>
      <iascf-pfs:SharePremiumOrdinarySharesEndingBalance numericContext='Group1999AsOf'>2475000000</iascf-pfs:SharePremiumOrdinarySharesEndingBalance>
      <iascf-pfs:RetainedProfitsAccumulatedLossesEndingBalance numericContext='Group1999AsOf'>33455000000</iascf-pfs:RetainedProfitsAccumulatedLossesEndingBalance>
      <iascf-pfs:TranslationReservesEndingBalance numericContext='Group1999AsOf'>-27000000</iascf-pfs:TranslationReservesEndingBalance>
      <novartis:ReservesTotalEndingBalance numericContext='Group1999AsOf'>35903000000</novartis:ReservesTotalEndingBalance>
      <iascf-pfs:ShareCapitalOrdinarySharesEndingBalance numericContext='Group1999AsOf'>1443000000</iascf-pfs:ShareCapitalOrdinarySharesEndingBalance>
      <iascf-pfs:TreasurySharesEndingBalance numericContext='Group1999AsOf'>-130000000</iascf-pfs:TreasurySharesEndingBalance>
      <iascf-pfs:EquityTotalEndingBalance numericContext='Group1999AsOf'>37216000000</iascf-pfs:EquityTotalEndingBalance>
      <iascf-pfs:RetainedProfitsAccumulatedLossesChangesPaymentsCashDividends numericContext='Group2000ForPeriod'>2064000000</iascf-pfs:RetainedProfitsAccumulatedLossesChangesPaymentsCashDividends>
      <novartis:PaymentsCashDividends numericContext='Group2000ForPeriod'>2064000000</novartis:PaymentsCashDividends>
      <iascf-pfs:EquityTotalChangesPaymentsCashDividends numericContext='Group2000ForPeriod'>2064000000</iascf-pfs:EquityTotalChangesPaymentsCashDividends>
      <iascf-pfs:RetainedProfitsAccumulatedLossesChangesTransferSharePremium numericContext='Group2000ForPeriod'>-2186000000</iascf-pfs:RetainedProfitsAccumulatedLossesChangesTransferSharePremium>
      <iascf-pfs:RetainedProfitsAccumulatedLossesChangesTransferSharePremium numericContext='Group2000ForPeriod'>2186000000</iascf-pfs:RetainedProfitsAccumulatedLossesChangesTransferSharePremium>
      <iascf-pfs:RetainedProfitsAccumulatedLossesChangesPurchaseTreasuryShares numericContext='Group2000ForPeriod'>-1156000000</iascf-pfs:RetainedProfitsAccumulatedLossesChangesPurchaseTreasuryShares>
      <novartis:PurchaseTreasuryShares numericContext='Group2000ForPeriod'>-1156000000</novartis:PurchaseTreasuryShares>
      <iascf-pfs:TreasurySharesChangesPurchaseTreasuryShares numericContext='Group2000ForPeriod'>-9000000</iascf-pfs:TreasurySharesChangesPurchaseTreasuryShares>
      <iascf-pfs:EquityTotalChangesPurchaseTreasuryShares numericContext='Group2000ForPeriod'>-1165000000</iascf-pfs:EquityTotalChangesPurchaseTreasuryShares>
      <novartis:RetainedProfitsAccumulatedLossesChangesEffectAgribusinessSpinOff numericContext='Group2000ForPeriod'>-3655000000</novartis:RetainedProfitsAccumulatedLossesChangesEffectAgribusinessSpinOff>
      <novartis:EffectAgribusinessSpinOff numericContext='Group2000ForPeriod'>-109000000</novartis:EffectAgribusinessSpinOff>
      <novartis:ReservesTotalChangesEffectAgribusinessSpinOff numericContext='Group2000ForPeriod'>-3764000000</novartis:ReservesTotalChangesEffectAgribusinessSpinOff>
      <novartis:EquityTotalChangesEffectAgribusinessSpinOff numericContext='Group2000ForPeriod'>-3764000000</novartis:EquityTotalChangesEffectAgribusinessSpinOff>
      <iascf-pfs:TranslationReservesChangesForeignCurrencyTranslationEffect numericContext='Group2000ForPeriod'>-571000000</iascf-pfs:TranslationReservesChangesForeignCurrencyTranslationEffect>
      <novartis:ForeignCurrencyTranslationEffect numericContext='Group2000ForPeriod'>-571000000</novartis:ForeignCurrencyTranslationEffect>
      <iascf-pfs:EquityTotalChangesForeignCurrencyTranslationEffect numericContext='Group2000ForPeriod'>-571000000</iascf-pfs:EquityTotalChangesForeignCurrencyTranslationEffect>
      </group>

I want to access and store data for child nodes such as RevenueFunction, CostSalesFunction, GrossProfitFunction , MarketingDistributionCostsFunction and so on for different years which is here 2000 and 2001.

我想访问和存储子节点的数据,例如RevenueFunction,CostSalesFunction,GrossProfitFunction,MarketingDistributionCostsFunction等,这些年份在2000年和2001年。

My program:

import xml.etree.ElementTree as ET

tree = ET.parse('XMLData.xml')
root = tree.getroot()

ns = {'real_data': 'http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15',
  'role_data': 'http://www.xbrl.org/taxonomy/int/fr/ias/pfs/2002-11-15/Novartis-2002-11-15'}

for data in root.findall('real_data:RevenueFunction', ns):
    print (data.text)

Output:

32038000000
35805000000

Now I want to know the numericContext contains which year. I am not able access the numericContext. How to do that.

现在我想知道numericContext包含哪一年。我无法访问numericContext。怎么做。

Or should I use lxml to get the data. As I am confused I don't know how to do.

或者我应该使用lxml来获取数据。因为我很困惑,我不知道该怎么做。

from lxml import etree
tree = etree.parse("XMLData.xml")
root = tree.getroot()
root.findall('iascf-pfs:RevenueFunction', root.nsmap)

Output: Error

    ---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-21-37cc8ca4da37> in <module>()
      2 tree = etree.parse("XMLData.xml")
      3 root = tree.getroot()
----> 4 root.findall('RevenueFunction', root.nsmap)
      5 

src/lxml/lxml.etree.pyx in lxml.etree._Element.findall (src\lxml\lxml.etree.c:61450)()

c:\pandas\venv\lib\site-packages\lxml-3.5.0-py2.7-win32.egg\lxml\_elementpath.pyc in findall(elem, path, namespaces)
    302 
    303 def findall(elem, path, namespaces=None):
--> 304     return list(iterfind(elem, path, namespaces))
    305 
    306 

c:\pandas\venv\lib\site-packages\lxml-3.5.0-py2.7-win32.egg\lxml\_elementpath.pyc in iterfind(elem, path, namespaces)
    275 
    276 def iterfind(elem, path, namespaces=None):
--> 277     selector = _build_path_iterator(path, namespaces)
    278     result = iter((elem,))
    279     for select in selector:

c:\pandas\venv\lib\site-packages\lxml-3.5.0-py2.7-win32.egg\lxml\_elementpath.pyc in _build_path_iterator(path, namespaces)
    232     """compile selector pattern"""
    233     if namespaces and (None in namespaces or '' in namespaces):
--> 234         raise ValueError("empty namespace prefix is not supported in ElementPath")
    235     if path[-1:] == "/":
    236         path += "*"  # implicit all (FIXME: keep this?)

ValueError: empty namespace prefix is not supported in ElementPath

3 个解决方案

#1


0  

You can use Element.get to get an attribute of the element:

您可以使用Element.get来获取元素的属性:

from lxml import etree
tree = etree.parse("XMLData.xml")
root = tree.getroot()
for x in root.findall('iascf-pfs:RevenueFunction', root.nsmap):
    print(x.get('numericContext'))

#2


0  

import xml.etree.ElementTree as ET
import re
tree = ET.parse('XMLData.xml')
root = tree.getroot()

ns = {'real_data': 'http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15'}
Stand_Net_Sales={}
for data in root.findall('real_data:RevenueFunction', ns):
    Stand_Net_Sales[int(re.sub("\D", "", data.attrib['numericContext']))] = float(data.text)

print Stand_Net_Sales

Output

{2000: 35805000000.0, 2001: 32038000000.0}

#3


0  

This solution search in all nodes for childs containing 'RevenueFunction' using child.tag:

此解决方案使用child.tag在所有节点中搜索包含“RevenueFunction”的子节点:

import xml.etree.ElementTree as ET
tree = ET.parse('XMLData.xml')
root = tree.getroot()

for child in root:
    if 'RevenueFunction' in child.tag:
        print child.text

output:
32038000000
35805000000

输出:32038000000 35805000000

#1


0  

You can use Element.get to get an attribute of the element:

您可以使用Element.get来获取元素的属性:

from lxml import etree
tree = etree.parse("XMLData.xml")
root = tree.getroot()
for x in root.findall('iascf-pfs:RevenueFunction', root.nsmap):
    print(x.get('numericContext'))

#2


0  

import xml.etree.ElementTree as ET
import re
tree = ET.parse('XMLData.xml')
root = tree.getroot()

ns = {'real_data': 'http://www.xbrl.org/taxonomy/int/fr/ias/ci/pfs/2002-11-15'}
Stand_Net_Sales={}
for data in root.findall('real_data:RevenueFunction', ns):
    Stand_Net_Sales[int(re.sub("\D", "", data.attrib['numericContext']))] = float(data.text)

print Stand_Net_Sales

Output

{2000: 35805000000.0, 2001: 32038000000.0}

#3


0  

This solution search in all nodes for childs containing 'RevenueFunction' using child.tag:

此解决方案使用child.tag在所有节点中搜索包含“RevenueFunction”的子节点:

import xml.etree.ElementTree as ET
tree = ET.parse('XMLData.xml')
root = tree.getroot()

for child in root:
    if 'RevenueFunction' in child.tag:
        print child.text

output:
32038000000
35805000000

输出:32038000000 35805000000