5
にXMLを変換します。PowerShellの - 私は、次のコードを使用してCSVにXMLを変換することができましたCSV
#read from file
[xml]$inputFile = Get-Content "c:\pstest\test.xml"
#export xml as csv
$inputFile.Transaction.ChildNodes | Export-Csv "c:\pstest\test.csv" -NoTypeInformation -Delimiter:";" -Encoding:UTF8
ファイルは、たとえば、子ノードのいずれかのタイプを持つ唯一のルートノードが含まれている場合、それは動作します:
<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>1</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515552017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>2</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515622017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>3</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515972017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
</Transaction>
出力は以下のようになりますように:素晴らしいです
"RecordID";"SequenceNumber";"TransactionType";"ActionCode";"TransactionID";"SellerCode";"BuyerCode";"TransactionReference";"TransactionDescription1";"TransactionDescription2";"DocumentType";"DocumentNumber";"DocumentDate";"DocumentAmount";"CurrencyCode";"TransactionAmount";"TransactionDueDate";"AdditionalInformation1";"AdditionalInformation2";"HashCode"
"02";"1";"01";"01";"17500515552017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
"02";"2";"01";"01";"17500515622017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
"02";"3";"01";"01";"17500515972017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
。
しかし、現実には、入力ファイルには、「ヘッダ行」情報、TXNHEADタグを持っている
<?xml version="1.0" encoding="UTF-8"?>
<Transaction>
<TXNHEAD>
<RecordID>01</RecordID>
<FileName>001</FileName>
<IntermediaryCode>19000033</IntermediaryCode>
<ActualizationDate>20170314</ActualizationDate>
<SequenceNumber>001</SequenceNumber>
<NumberofRecords>3</NumberofRecords>
<AmountofRecords>30000</AmountofRecords>
</TXNHEAD>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>1</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515552017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>2</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515622017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
<TXNDETAIL>
<RecordID>02</RecordID>
<SequenceNumber>3</SequenceNumber>
<TransactionType>01</TransactionType>
<ActionCode>01</ActionCode>
<TransactionID>17500515972017001</TransactionID>
<SellerCode>2200919TRY</SellerCode>
<BuyerCode>KOCZER</BuyerCode>
<TransactionReference> </TransactionReference>
<TransactionDescription1> </TransactionDescription1>
<TransactionDescription2> </TransactionDescription2>
<DocumentType>01</DocumentType>
<DocumentNumber>XXXXXXXXXXX</DocumentNumber>
<DocumentDate>20170301</DocumentDate>
<DocumentAmount>10000</DocumentAmount>
<CurrencyCode>949</CurrencyCode>
<TransactionAmount>10000</TransactionAmount>
<TransactionDueDate>20170505</TransactionDueDate>
<AdditionalInformation1> </AdditionalInformation1>
<AdditionalInformation2> </AdditionalInformation2>
<HashCode>XXXXXXXX</HashCode>
</TXNDETAIL>
</Transaction>
同じコードを適用する場合、私が手:私はこれをしようとしていた場合
"RecordID";"FileName";"IntermediaryCode";"ActualizationDate";"SequenceNumber";"NumberofRecords";"AmountofRecords"
"01";"001";"19000033";"20170314";"001";"3";"30000"
"02";;;;"1";;
"02";;;;"2";;
"02";;;;"3";;
私が手
#read from file
[xml]$inputFile = Get-Content "c:\pstest\test.xml"
#export xml as csv
$inputFile.Transaction.TXNHEAD.ChildNodes | Export-Csv "c:\pstest\test.csv" -NoTypeInformation -Delimiter:";" -Encoding:UTF8
:コードではなく、ただ頭を取得する
私が達成しようとしています何"#text"
"01"
"001"
"19000033"
"20170314"
"001"
"3"
"30000"
、この出力されます:
"RecordID";"FileName";"IntermediaryCode";"ActualizationDate";"SequenceNumber";"NumberofRecords";"AmountofRecords"
"01";"001";"19000033";"20170314";"001";"3";"30000"
"RecordID";"SequenceNumber";"TransactionType";"ActionCode";"TransactionID";"SellerCode";"BuyerCode";"TransactionReference";"TransactionDescription1";"TransactionDescription2";"DocumentType";"DocumentNumber";"DocumentDate";"DocumentAmount";"CurrencyCode";"TransactionAmount";"TransactionDueDate";"AdditionalInformation1";"AdditionalInformation2";"HashCode"
"02";"1";"01";"01";"17500515552017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
"02";"2";"01";"01";"17500515622017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
"02";"3";"01";"01";"17500515972017001";"2200919TRY";"KOCZER";"";"";"";"01";"XXXXXXXXXXX";"20170301";"10000";"949";"10000";"20170505";"";"";"XXXXXXXX"
私が間違って何をしているのですか?
。 – Vesper
彼はしません。もう一度 –
を読んでください。彼は言った: "私は次の出力が欲しい:"と出力は 'RecordID'から始まるタイプ情報の行を含んでいます。質問の最後のコードブロックを確認してください。 – Vesper