【发布时间】:2019-12-19 20:16:11
【问题描述】:
我正在学习java。 我无法使用 Java 解析以下 XML。有人可以解释一下如何解析这个 xml 吗?
即使我尝试过一些示例代码。那没有用。 我想用
阅读交易标签下的所有礼物事务 ID
金额
- 请求的金额
- 状态
- 钱包详情
<?xml version="1.0" encoding="UTF-8"?>
<ns2:getFundAccountHistoryResponse xmlns:ns2="http://schema.products.sports.bet.com/fundingService" xmlns="http://schema.products.sports.bet.com/promoCommonTypes" xmlns:ns3="http://schema.products.sports.bet.com/fundingTypes">
<ns2:status code="OK" />
<ns2:transactions>
<ns3:transaction id="74608009" amount="-200.00" requestedAmount="-200.00" status="COMPLETE">
<ns3:wallets>
<ns3:wallet>
<ns3:walletType>NON_WITHDRAWABLE</ns3:walletType>
<ns3:totalBalance>0.00</ns3:totalBalance>
</ns3:wallet>
</ns3:wallets>
<ns3:transactionFunds>
<ns3:transactionFund>
<ns3:externalFundRef id="CPM-1073070" provider="OB.CUST" />
<ns3:transactionFundItems>
<ns3:transactionFundItem forfeited="false">
<ns3:type>CASH</ns3:type>
<ns3:amount>-200.00</ns3:amount>
</ns3:transactionFundItem>
</ns3:transactionFundItems>
</ns3:transactionFund>
</ns3:transactionFunds>
<ns3:transactionType>BSTK</ns3:transactionType>
<ns3:creationDate>2019-08-10T17:44:31</ns3:creationDate>
<ns3:publishedTransactionDate>2019-08-10T17:44:31</ns3:publishedTransactionDate>
<ns3:transactionDate>2019-08-10T17:44:31</ns3:transactionDate>
<ns3:fundingActivity>
<ns3:externalActivityRef id="60077338_0" provider="OB.BET" />
<ns3:type>STAKE</ns3:type>
<ns3:fundingOperations>
<ns3:fundingOperation>
<ns3:externalOperationRef id="b703c6b9-b9aa-4c5d-b6cc-1321d7f2a7a9" provider="OB.BET" />
<ns3:operationType>ESB</ns3:operationType>
<ns3:status>OPEN</ns3:status>
</ns3:fundingOperation>
</ns3:fundingOperations>
</ns3:fundingActivity>
<ns3:description>|Gold Coast Titans| @ 4.75</ns3:description>
</ns3:transaction>
<ns3:transaction id="74606629" amount="-411.00" requestedAmount="-411.00" status="COMPLETE">
<ns3:wallets>
<ns3:wallet>
<ns3:walletType>NON_WITHDRAWABLE</ns3:walletType>
<ns3:totalBalance>0.00</ns3:totalBalance>
</ns3:wallet>
</ns3:wallets>
<ns3:transactionFunds>
<ns3:transactionFund>
<ns3:externalFundRef id="CPM-1033856" provider="OB.CUST" />
<ns3:transactionFundItems>
<ns3:transactionFundItem forfeited="false">
<ns3:type>CASH</ns3:type>
<ns3:amount>-14.04</ns3:amount>
</ns3:transactionFundItem>
</ns3:transactionFundItems>
</ns3:transactionFund>
<ns3:transactionFund>
<ns3:externalFundRef id="CPM-1073070" provider="OB.CUST" />
<ns3:transactionFundItems>
<ns3:transactionFundItem forfeited="false">
<ns3:type>CASH</ns3:type>
<ns3:amount>-396.96</ns3:amount>
</ns3:transactionFundItem>
</ns3:transactionFundItems>
</ns3:transactionFund>
</ns3:transactionFunds>
<ns3:transactionType>BSTK</ns3:transactionType>
<ns3:creationDate>2019-08-10T17:42:08</ns3:creationDate>
<ns3:publishedTransactionDate>2019-08-10T17:42:08</ns3:publishedTransactionDate>
<ns3:transactionDate>2019-08-10T17:42:08</ns3:transactionDate>
<ns3:fundingActivity>
<ns3:externalActivityRef id="60076164_0" provider="OB.BET" />
<ns3:type>STAKE</ns3:type>
<ns3:fundingOperations>
<ns3:fundingOperation>
<ns3:externalOperationRef id="9700030e-8057-4ca4-8a1f-74ba9799980d" provider="OB.BET" />
<ns3:operationType>ESB</ns3:operationType>
<ns3:status>OPEN</ns3:status>
</ns3:fundingOperation>
</ns3:fundingOperations>
</ns3:fundingActivity>
<ns3:description>|Over| (49.0) @ 1.87</ns3:description>
</ns3:transaction>
</ns2:transactions>
</ns2:getFundAccountHistoryResponse>
我想打印交易标签下的所有详细信息。
【问题讨论】:
-
一种方法是在
xml文件的位置打开Stream并将所有内容写入StringBuilder,然后您只需将其转换为String和然后使用split()函数获取想要的标签 -
@PhillAlexakis,你能告诉我怎么做吗?
-
@Hari 当然我会给你看一个演示,记住字符串解析是一个相当长的过程
标签: java parsing xml-parsing