INURIA
Temporär Suspendiert
- Registriert
- 16 Juli 2013
- Beiträge
- 102
Hallo, folgendendes Problem, welches mich seit Tagen zur Verzweiflung bringt:
Ich möchte in VB.NET eine XML einlesen (Bestelleingänge) und diese in einer Listview anzeigen lassen - soweit funktioniert dies aus ohne Probleme. Leider schaffe ich es aber nicht, wenn mehrere Artikel in einer Bestellung geordert werden, diese auch anzuzeigen - es wird immer nur der erste Artikel in der Bestellung angezeigt![Dozey :dozey: :dozey:](https://ngb.to/images/smilies/dozey.png)
Wie man aber in der XML sehen kann, sind 2 Bestellungen vorhanden mit jeweils 2 Artikeln. Ich habe versucht mit den wildesten For-each konstruktionen das ganze irgendwie hinzubekommen, aber leider ohne Erfolg - entweder wird da eine dauerschleife draus, oder es wird gar nix mehr angezeigt. Ich hoffe ihr könnt mir irgendwie helfen.
Danke schon einmal![Beer :beer: :beer:](https://ngb.to/images/smilies/beer.png)
Hier der Vb-Code und unten die XML, welche normalerweise per API von einem Server geladen wird.
[src=vbnet] Try
xmlDoc.Load("test.xml")
For Each xmlNode As Xml.XmlElement In xmlDoc.SelectNodes("result/orders/order")
Dim status As String = xmlNode.SelectSingleNode("status").InnerText
Dim items As ListViewItem = ListView1.Items.Add(xmlNode.SelectSingleNode("items/item/name").InnerText)
Dim eMail As String = xmlNode.SelectSingleNode("client/email").InnerText
Dim quantity As String = xmlNode.SelectSingleNode("items/item/qty").InnerText
Dim firstName As String = xmlNode.SelectSingleNode("client/first_name").InnerText
Dim lastName As String = xmlNode.SelectSingleNode("client/last_name").InnerText
Dim productName As String = xmlNode.SelectSingleNode("items/item/name").InnerText
Dim total As String = xmlNode.SelectSingleNode("total").InnerText
Dim created As String = xmlNode.SelectSingleNode("created").InnerText
Dim order_no As String = xmlNode.SelectSingleNode("order_no").InnerText
items.SubItems.Add(quantity)
items.SubItems.Add(total)
items.SubItems.Add(firstName + " " + lastName)
items.SubItems.Add(eMail)
items.SubItems.Add(created)
items.SubItems.Add(status)
items.SubItems.Add(order_no)
' editable | shipped | canceled
If Status = "editable" Then
completeOrder(Order_no, eMail, productName, quantity)
End If
Next
Catch ex As Exception
ListBox1.Items.Add(ex.Message)
End Try[/src]
[src=xml]<result>
<success>1</success>
<orders>
<paging>
<total>1234</total>
<page>1</page>
<pages>139</pages>
<per_page>20</per_page>
</paging>
<order>
<order_no>000-000-000</order_no>
<total>50.99</total>
<shipping>0.00</shipping>
<max_shipping_date>2020-08-07</max_shipping_date>
<payment>PAL</payment>
<status>editable</status>
<invoice_no>999999-88888</invoice_no>
<comment_client/>
<comment_merchant/>
<created>2020-08-05 09:48:27</created>
<InLogistics>0</InLogistics>
<client>
<client_id>41019710</client_id>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
<email>test@email.de</email>
<phone>123-123-123</phone>
</client>
<delivery_address>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
</delivery_address>
<items>
<item>
<item_id>83969739</item_id>
<product_id>3133287034</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 1 - Artikel 1
</name>
<name_add/>
<qty>2</qty>
<price>1.59</price>
<price_sum>3.18</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
<item>
<item_id>83969744</item_id>
<product_id>3133286649</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 1 - Artikel 2
</name>
<name_add/>
<qty>2</qty>
<price>1.69</price>
<price_sum>3.38</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
</items>
<coupon/>
</order>
<order>
<order_no>111-222-333</order_no>
<total>99.99</total>
<shipping>0.00</shipping>
<max_shipping_date>2020-08-07</max_shipping_date>
<payment>PAL</payment>
<status>editable</status>
<invoice_no>999999-88888</invoice_no>
<comment_client/>
<comment_merchant/>
<created>2020-08-05 09:48:27</created>
<InLogistics>0</InLogistics>
<client>
<client_id>41019710</client_id>
<gender>Frau</gender>
<first_name>maxi</first_name>
<last_name>musterfrau</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
<email>test@email.de</email>
<phone>123-123-123</phone>
</client>
<delivery_address>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
</delivery_address>
<items>
<item>
<item_id>83969739</item_id>
<product_id>3133287034</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 2 - Artikel 1
</name>
<name_add/>
<qty>2</qty>
<price>1.59</price>
<price_sum>3.18</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
<item>
<item_id>83969744</item_id>
<product_id>3133286649</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 2 - Artikel 2
</name>
<name_add/>
<qty>2</qty>
<price>1.69</price>
<price_sum>3.38</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
</items>
<coupon/>
</order>
</orders>
</result>[/src]
Ich möchte in VB.NET eine XML einlesen (Bestelleingänge) und diese in einer Listview anzeigen lassen - soweit funktioniert dies aus ohne Probleme. Leider schaffe ich es aber nicht, wenn mehrere Artikel in einer Bestellung geordert werden, diese auch anzuzeigen - es wird immer nur der erste Artikel in der Bestellung angezeigt
![Dozey :dozey: :dozey:](https://ngb.to/images/smilies/dozey.png)
Wie man aber in der XML sehen kann, sind 2 Bestellungen vorhanden mit jeweils 2 Artikeln. Ich habe versucht mit den wildesten For-each konstruktionen das ganze irgendwie hinzubekommen, aber leider ohne Erfolg - entweder wird da eine dauerschleife draus, oder es wird gar nix mehr angezeigt. Ich hoffe ihr könnt mir irgendwie helfen.
Danke schon einmal
![Beer :beer: :beer:](https://ngb.to/images/smilies/beer.png)
Hier der Vb-Code und unten die XML, welche normalerweise per API von einem Server geladen wird.
[src=vbnet] Try
xmlDoc.Load("test.xml")
For Each xmlNode As Xml.XmlElement In xmlDoc.SelectNodes("result/orders/order")
Dim status As String = xmlNode.SelectSingleNode("status").InnerText
Dim items As ListViewItem = ListView1.Items.Add(xmlNode.SelectSingleNode("items/item/name").InnerText)
Dim eMail As String = xmlNode.SelectSingleNode("client/email").InnerText
Dim quantity As String = xmlNode.SelectSingleNode("items/item/qty").InnerText
Dim firstName As String = xmlNode.SelectSingleNode("client/first_name").InnerText
Dim lastName As String = xmlNode.SelectSingleNode("client/last_name").InnerText
Dim productName As String = xmlNode.SelectSingleNode("items/item/name").InnerText
Dim total As String = xmlNode.SelectSingleNode("total").InnerText
Dim created As String = xmlNode.SelectSingleNode("created").InnerText
Dim order_no As String = xmlNode.SelectSingleNode("order_no").InnerText
items.SubItems.Add(quantity)
items.SubItems.Add(total)
items.SubItems.Add(firstName + " " + lastName)
items.SubItems.Add(eMail)
items.SubItems.Add(created)
items.SubItems.Add(status)
items.SubItems.Add(order_no)
' editable | shipped | canceled
If Status = "editable" Then
completeOrder(Order_no, eMail, productName, quantity)
End If
Next
Catch ex As Exception
ListBox1.Items.Add(ex.Message)
End Try[/src]
[src=xml]<result>
<success>1</success>
<orders>
<paging>
<total>1234</total>
<page>1</page>
<pages>139</pages>
<per_page>20</per_page>
</paging>
<order>
<order_no>000-000-000</order_no>
<total>50.99</total>
<shipping>0.00</shipping>
<max_shipping_date>2020-08-07</max_shipping_date>
<payment>PAL</payment>
<status>editable</status>
<invoice_no>999999-88888</invoice_no>
<comment_client/>
<comment_merchant/>
<created>2020-08-05 09:48:27</created>
<InLogistics>0</InLogistics>
<client>
<client_id>41019710</client_id>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
<email>test@email.de</email>
<phone>123-123-123</phone>
</client>
<delivery_address>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
</delivery_address>
<items>
<item>
<item_id>83969739</item_id>
<product_id>3133287034</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 1 - Artikel 1
</name>
<name_add/>
<qty>2</qty>
<price>1.59</price>
<price_sum>3.18</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
<item>
<item_id>83969744</item_id>
<product_id>3133286649</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 1 - Artikel 2
</name>
<name_add/>
<qty>2</qty>
<price>1.69</price>
<price_sum>3.38</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
</items>
<coupon/>
</order>
<order>
<order_no>111-222-333</order_no>
<total>99.99</total>
<shipping>0.00</shipping>
<max_shipping_date>2020-08-07</max_shipping_date>
<payment>PAL</payment>
<status>editable</status>
<invoice_no>999999-88888</invoice_no>
<comment_client/>
<comment_merchant/>
<created>2020-08-05 09:48:27</created>
<InLogistics>0</InLogistics>
<client>
<client_id>41019710</client_id>
<gender>Frau</gender>
<first_name>maxi</first_name>
<last_name>musterfrau</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
<email>test@email.de</email>
<phone>123-123-123</phone>
</client>
<delivery_address>
<gender>Herr</gender>
<first_name>max</first_name>
<last_name>mustertyp</last_name>
<company/>
<street>Muster Straße</street>
<street_no>8</street_no>
<address_add/>
<zip_code>00000</zip_code>
<city>Teststadt</city>
<country>DE</country>
</delivery_address>
<items>
<item>
<item_id>83969739</item_id>
<product_id>3133287034</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 2 - Artikel 1
</name>
<name_add/>
<qty>2</qty>
<price>1.59</price>
<price_sum>3.18</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
<item>
<item_id>83969744</item_id>
<product_id>3133286649</product_id>
<variant_id>0</variant_id>
<product_art_no/>
<name>
Bestellung 2 - Artikel 2
</name>
<name_add/>
<qty>2</qty>
<price>1.69</price>
<price_sum>3.38</price_sum>
<tax>1</tax>
<country/>
<city/>
<address/>
<zip_code/>
</item>
</items>
<coupon/>
</order>
</orders>
</result>[/src]