XML数据到平面阵列

时间:2011-09-17 09:45:52

标签: xml arrays flat

我有一个(可能)简单的问题,但我目前无法解决它。

我有一个这样的格式化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>nix@inter.net</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>nix@inter.net</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寻找可能的,几乎匹配的解决方案来解决它,但也许我的头脑中有一个封锁。

也许有人可以帮助我。

1 个答案:

答案 0 :(得分: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.

这是否开始解决您的问题?或者我错了吗?