1
Matlab regexpを使用してxmlファイルを解析しようとしています。具体的には、 「deposits」と「/ deposits」の間に出現する「curvepoint」という単語のすべての発生の配列を取得するのが好きです。そこで、以下のXMLのためには、それぞれ「curvepointの間に散在他のテキストがたくさんあるとして、以下の「他の2つの単語間の正規表現のマッチングの単語(Matlab regexp)
<curvepoint>
<curvepoint>
<curvepoint>
<curvepoint>
<curvepoint>
<curvepoint>
」
私の試みは動作しません
のような[6x1]配列でなければなりません"言葉の出現率と先読み/背中が、私はこれをどう扱うかわかりません。
regexp(XMLText,'(?<=<deposits>)(<curvepoint>)(?=</deposits>)','match')'
XMLTEXTは、XMLを解析するために正規表現を使用しないでください
<?xml version="1.0" encoding="utf-8"?>
<interestRateCurve>
<effectiveasof>2016-11-07</effectiveasof>
<currency>EUR</currency>
<baddayconvention>M</baddayconvention>
<deposits>
<daycountconvention>ACT/360</daycountconvention>
<snaptime>2016-11-04T15:00:00.000Z</snaptime>
<spotdate>2016-11-09</spotdate>
<calendars>
<calendar>none</calendar>
</calendars>
<curvepoint>
<tenor>1M</tenor>
<maturitydate>2016-12-09</maturitydate>
<parrate>-0.00373</parrate>
</curvepoint>
<curvepoint>
<tenor>2M</tenor>
<maturitydate>2017-01-09</maturitydate>
<parrate>-0.00339</parrate>
</curvepoint>
<curvepoint>
<tenor>3M</tenor>
<maturitydate>2017-02-09</maturitydate>
<parrate>-0.00312</parrate>
</curvepoint>
<curvepoint>
<tenor>6M</tenor>
<maturitydate>2017-05-09</maturitydate>
<parrate>-0.00213</parrate>
</curvepoint>
<curvepoint>
<tenor>9M</tenor>
<maturitydate>2017-08-09</maturitydate>
<parrate>-0.0013</parrate>
</curvepoint>
<curvepoint>
<tenor>1Y</tenor>
<maturitydate>2017-11-09</maturitydate>
<parrate>-0.00071</parrate>
</curvepoint>
</deposits>
<swaps>
<fixeddaycountconvention>30/360</fixeddaycountconvention>
<floatingdaycountconvention>ACT/360</floatingdaycountconvention>
<fixedpaymentfrequency>1Y</fixedpaymentfrequency>
<floatingpaymentfrequency>6M</floatingpaymentfrequency>
<snaptime>2016-11-04T15:00:00.000Z</snaptime>
<spotdate>2016-11-09</spotdate>
<calendars>
<calendar>none</calendar>
</calendars>
<curvepoint>
<tenor>2Y</tenor>
<maturitydate>2018-11-09</maturitydate>
<parrate>-0.00157</parrate>
</curvepoint>
<curvepoint>
<tenor>3Y</tenor>
<maturitydate>2019-11-09</maturitydate>
<parrate>-0.00115</parrate>
</curvepoint>
<curvepoint>
<tenor>4Y</tenor>
<maturitydate>2020-11-09</maturitydate>
<parrate>-0.00059</parrate>
</curvepoint>
<curvepoint>
<tenor>5Y</tenor>
<maturitydate>2021-11-09</maturitydate>
<parrate>0.00017</parrate>
</curvepoint>
<curvepoint>
<tenor>6Y</tenor>
<maturitydate>2022-11-09</maturitydate>
<parrate>0.00108</parrate>
</curvepoint>
<curvepoint>
<tenor>7Y</tenor>
<maturitydate>2023-11-09</maturitydate>
<parrate>0.0021</parrate>
</curvepoint>
<curvepoint>
<tenor>8Y</tenor>
<maturitydate>2024-11-09</maturitydate>
<parrate>0.00316</parrate>
</curvepoint>
<curvepoint>
<tenor>9Y</tenor>
<maturitydate>2025-11-09</maturitydate>
<parrate>0.00419</parrate>
</curvepoint>
<curvepoint>
<tenor>10Y</tenor>
<maturitydate>2026-11-09</maturitydate>
<parrate>0.00513</parrate>
</curvepoint>
<curvepoint>
<tenor>12Y</tenor>
<maturitydate>2028-11-09</maturitydate>
<parrate>0.00673</parrate>
</curvepoint>
<curvepoint>
<tenor>15Y</tenor>
<maturitydate>2031-11-09</maturitydate>
<parrate>0.00838</parrate>
</curvepoint>
<curvepoint>
<tenor>20Y</tenor>
<maturitydate>2036-11-09</maturitydate>
<parrate>0.00966</parrate>
</curvepoint>
<curvepoint>
<tenor>30Y</tenor>
<maturitydate>2046-11-09</maturitydate>
<parrate>0.01006</parrate>
</curvepoint>
</swaps>
</interestRateCurve>
ありがとうkj、私はこれを達成するためにmatlabのxml機能に取り組む時間がありません(これは私の "プロジェクト"のごく小さな部分です)。私は正規表現のロジックがあいまいなので、正規表現は脆弱であると思います。正規表現の経験豊富なコーダーは、厳密な表現を見つけることができます。この質問を具体的な解決策を得るためにはかなり具体的なものにするために時間を費やしました。 – user152112
あなたは望みどおりに行いますが、本質的にも実用的にも、XMLを解析するための正規表現の正規表現がどれくらい正確か分かっていれば、この質問をしないでください。これらのリスクは、他の場所でも十分に文書化されています。私は、あなたが正しい方法でそれをやることを学ばなければならないよりも、これらのリスクを再ハッシュする時間が少なくて済みます。 – kjhughes