XML ファイル:
<Partner>
...
</Partner>
<Partner>
<K1>10</K1>
<K2>3</K2>
<K3>5254304</K3>
<K4>test name</K4>
<K5>637.51</K5>
<K6>159.38</K6>
<K7>802.39</K7>
<K8>0.00</K8>
<K9>802.39</K9>
<Invoices>
<Invoice>
<R1>1</R1>
<R2>4-02R0113-12</R2>
<R3>2014-12-29</R3>
<R4>2014-12-29</R4>
<R5>398</R5>
<R6>637.51</R6>
<R7>159.38</R7>
<R8>802.39</R8>
<R9>0.00</R9>
<R10>802.39</R10>
</Invoice>
</Invoices>
</Partner>
<Partner>
...
</Partner>
私の XML ファイルには、繰り返しノードがあり<Partner>
ます。各パートナーには、 node に書き込まれた独自の識別番号があります<K3>
。
すべてのパートナーは、複数の請求書を持つことができます。
、、の値がわかっている請求書の値<R6>
を見つけて読み取る必要があります。<R7>
<R2>
<R3>
<R8>
検索条件が複数のフィールド<R2>
, <R3>
,<R8>
である特定の請求書を検索し、検索条件がフィールドであるパートナーのフィールドを検索し、および<K3>
のフィールド値を取得するにはどうすればよいですか?<R6>
<R7>
に複数の条件を追加する方法はSelectSingleNode
?
私のコード:
procedure TfrmTest.TestReadOmniXML;
var
xml: IXMLDocument;
iNodePartner, iNodePartnerInvoice, iNodePartnerInvoiceR6, iNodePartnerInvoiceR7 : IXMLNode;
begin
xml := CreateXMLDoc;
xml.Load('c:\test.xml');
iNodePartner := XML.SelectSingleNode('//Partner[K3=' + '0254304' + ']');
iNodePartnerInvoice := iNodePartner.SelectSingleNode(
//single query works OK
'.//Racuni/Racun[R2=' + '4-02R0113-12' + ']'
//but I need to add these fields also
// ' and [R3=' + '2014-12-29' + ']' +
// ' and [R8=' + '802.39' + ']'
);
if Assigned( iNodePartnerInvoice ) then
begin
iNodePartnerInvoiceR6 := iNodePartnerInvoice.SelectSingleNode('./R6');
Label1.Caption := iNodePartnerInvoiceR6.Text;
iNodePartnerInvoiceR7 := iNodePartnerInvoice.SelectSingleNode('./R7');
Label2.Caption := iNodePartnerInvoiceR7.Text;
end;
...
end;