2011-09-17 46 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來解決它自己,但也許我已經在我的頭immo封鎖。

也許有人可以幫助我。

+0

「儘可能平坦」是什麼意思? –

+0

嗯,*爲什麼*你想平坦的數據在第一位?另外,我不太確定我是否理解這個問題。通常,您只需將XML解析爲DOM樹並對其進行操作即可。爲什麼這不適合你? – phihag

+0

@Captain長頸鹿而不是'文字',他想要'文字'''。我不知道你爲什麼想這樣做。 – phihag

回答

0

這似乎是一個非常複雜的問題,所以我可能不明白這個問題。答案是解析XML,將其存儲在array[],從而(使用僞C表示法):

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 - 如果答案有幫助,請點擊答案旁邊的大綱複選標記,考慮***接受***。謝謝!我的名譽感謝你:-) –