2011-09-17 5 views
0

私は多分簡単な問題を持っていますが、私は現在解決できません。XMLデータをフラットアレイ

私はこのようなフォーマットされたXML文字列を持っている:

<?xml version="1.0" encoding="utf-8"?> 
<e5Notification xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xml.element5.com/2.3/ordernotification.xsd"> 
<OrderNotification> 
<Purchase> 
<PurchaseId>391489835</PurchaseId> 
<PurchaseDate>2011-09-17T11:37:52</PurchaseDate> 
<PurchaseOrigin>online</PurchaseOrigin> 
<PaymentCompleteDate>2011-09-17T11:37:52</PaymentCompleteDate> 
<PaymentStatus>test payment arrived</PaymentStatus> 
<CustomerData> 
<BillingContact> 
<LastName>User</LastName> 
<FirstName>Test</FirstName> 
<Email>[email protected]</Email> 
<Address> 
<Street1>Musterweg 123</Street1> 
<City>Musterhausen</City> 
<PostalCode>12345</PostalCode> 
<CountryId>DE</CountryId> 
<Country>Deutschland</Country> 
</Address> 
</BillingContact> 
<DeliveryContact> 
<LastName>User</LastName> 
<FirstName>Test</FirstName> 
<Email>[email protected]</Email> 
<Address> 
<Street1>Musterweg 123</Street1> 
<City>Musterhausen</City> 
<PostalCode>12345</PostalCode> 
<CountryId>DE</CountryId> 
<Country>Deutschland</Country> 
</Address> 
</DeliveryContact> 
<CustomerPaymentData> 
<PaymentMethod>Visa</PaymentMethod> 
<Currency>EUR</Currency> 
</CustomerPaymentData> 
<Language>Deutsch</Language> 
<RegName>Test User</RegName> 
<SubscribeNewsletter>false</SubscribeNewsletter> 
</CustomerData> 
<PurchaseItem> 
<RunningNo>1</RunningNo> 
<ProductId>1234567896</ProductId> 
<ProductName>Test-Product</ProductName> 
<NotificationNo>0</NotificationNo> 
<DeliveryType>Electronically</DeliveryType> 
<Currency>EUR</Currency> 
<Quantity>1</Quantity> 
<ProductSinglePrice>192.44</ProductSinglePrice> 
<VatPct>19.00</VatPct> 
<Discount>0.00</Discount> 
<ExtendedDownloadPrice>0.00</ExtendedDownloadPrice> 
<ManuelOrderPrice>0.00</ManuelOrderPrice> 
<ShippingPrice>0.00</ShippingPrice> 
<ShippingVatPct>19.00</ShippingVatPct> 
<Subscription> 
<Interval>Monthly without end</Interval> 
</Subscription> 
</PurchaseItem> 
</Purchase> 
</OrderNotification> 
</e5Notification> 

私はできるだけ平坦単純な配列にこれを変換したいです。

私はS-Oを可能な限り解決しようとしましたが、それは私自身で解決する解決策に近いものでしたが、おそらく私の頭の中に封鎖されています。

誰かが私を助けてくれるかもしれません。

+0

「できるだけフラット」とはどういう意味ですか? –

+0

うーん、*なぜ*最初にデータを平坦化しますか?また、私はその質問を理解しているかどうかはわかりません。通常は、XMLをDOMツリーに解析して操作します。なぜそれはあなたのために働かないのですか? – phihag

+0

@Captain Giraffe テキスト 'の代わりに、彼は' テキスト 'のようなものを望みます。私はなぜあなたがそれをしたいと思うか分かりません。 – phihag

答えて

0

これは圧倒的に複雑な問題のようですので、私はおそらくその質問を理解していません。答えは(擬似Cの表記を使用して)ので、array[]に格納する、XMLを解析することです:

array[0]: struct OrderNotification, consisting of one or more 
       struct Subscription, where each subscription has a collection of 
       struct Purchase, and each Purchase has some 
        struct PurchaseItem; 
array[1]: same as array[0] 
array[2]: same as array[0] 

usw. 

これは、あなたの質問に対処するために始めていますか?それとも私は間違っていますか?

+0

これは私を助けました^^私はそれを解決するために複雑に思っていました。ありがとうございました! –

+0

@Marcel - 答えが助けられた場合は、回答の横のチェックマークをクリックして***を受け入れることを考慮してください。ありがとう!私の評判はあなたに感謝します:-) –