none
.NET CORE | console app | Wie kann ich am besten den eBay GetOrders Response mit RestSharp parsen? RRS feed

  • Frage

  • Hallo zusammen,

    ich bin neu in der Benutzung von RestSharp und habe leider kein Beispiel gefunden für solch ein komplexes XML zu parsen.

    Daher würde es mich freuen wenn jemand mir hilft.

    Hier nun den eBay Response der analysiert werden muss:

    <?xml version="1.0" encoding="UTF-8"?>
    <GetOrdersResponse 
      xmlns="urn:ebay:apis:eBLBaseComponents">
      <Timestamp>2019-11-04T22:26:21.145Z</Timestamp>
      <Ack>Success</Ack>
      <Version>1131</Version>
      <Build>>E1131_CORE_APIXO_19102180_R1</Build>
      <PaginationResult>
        <TotalNumberOfPages>1</TotalNumberOfPages>
        <TotalNumberOfEntries>3</TotalNumberOfEntries>
      </PaginationResult>
      <HasMoreOrders>false</HasMoreOrders>
      <OrderArray>
        <Order>
          <OrderID>123395219748-0</OrderID>
          <OrderStatus>Completed</OrderStatus>
          <AdjustmentAmount currencyID="USD">0.0</AdjustmentAmount>
          <AmountPaid currencyID="USD">41.79</AmountPaid>
          <AmountSaved currencyID="USD">0.0</AmountSaved>
          <CheckoutStatus>
            <eBayPaymentStatus>NoPaymentFailure</eBayPaymentStatus>
            <LastModifiedTime>2019-10-08T19:25:08.000Z</LastModifiedTime>
            <PaymentMethod>CreditCard</PaymentMethod>
            <Status>Complete</Status>
            <IntegratedMerchantCreditCardEnabled>true</IntegratedMerchantCreditCardEnabled>
            <PaymentInstrument>CreditCard</PaymentInstrument>
          </CheckoutStatus>
          <ShippingDetails>
            <SalesTax>
              <SalesTaxPercent>0.0</SalesTaxPercent>
              <SalesTaxState></SalesTaxState>
              <ShippingIncludedInTax>false</ShippingIncludedInTax>
              <SalesTaxAmount currencyID="USD">0.0</SalesTaxAmount>
            </SalesTax>
            <ShippingServiceOptions>
              <ShippingService>USPSParcel</ShippingService>
              <ShippingServicePriority>1</ShippingServicePriority>
              <ExpeditedService>false</ExpeditedService>
              <ShippingTimeMin>2</ShippingTimeMin>
              <ShippingTimeMax>9</ShippingTimeMax>
            </ShippingServiceOptions>
            <ShippingServiceOptions>
              <ShippingService>Pickup</ShippingService>
              <ShippingServicePriority>3</ShippingServicePriority>
              <ExpeditedService>false</ExpeditedService>
            </ShippingServiceOptions>
            <SellingManagerSalesRecordNumber>109</SellingManagerSalesRecordNumber>
            <GetItFast>false</GetItFast>
          </ShippingDetails>
          <CreatedTime>2019-10-05T19:11:16.000Z</CreatedTime>
          <PaymentMethods>PayPal</PaymentMethods>
          <SellerEmail>r***l@g***l.com</SellerEmail>
          <ShippingAddress>
            <Name>w***s</Name>
            <Street1>7***d</Street1>
            <Street2></Street2>
            <CityName>p***a</CityName>
            <StateOrProvince>PA</StateOrProvince>
            <Country>US</Country>
            <CountryName>United States</CountryName>
            <Phone>2****8</Phone>
            <PostalCode>1***8-1**0</PostalCode>
            <AddressID>5***1</AddressID>
            <AddressOwner>eBay</AddressOwner>
            <ExternalAddressID></ExternalAddressID>
          </ShippingAddress>
          <ShippingServiceSelected>
            <ShippingService>USPSParcel</ShippingService>
            <ShippingServiceCost currencyID="USD">10.79</ShippingServiceCost>
          </ShippingServiceSelected>
          <Subtotal currencyID="USD">31.0</Subtotal>
          <Total currencyID="USD">41.79</Total>
          <TransactionArray>
            <Transaction>
              <Buyer>
                <Email>Invalid Request</Email>
                <UserFirstName>W***e</UserFirstName>
                <UserLastName>E***s</UserLastName>
              </Buyer>
              <ShippingDetails>
                <CalculatedShippingRate>
                  <OriginatingPostalCode>95125</OriginatingPostalCode>
                  <PackageDepth measurementSystem="English" unit="inches">5</PackageDepth>
                  <PackageLength measurementSystem="English" unit="inches">13</PackageLength>
                  <PackageWidth measurementSystem="English" unit="inches">6</PackageWidth>
                  <PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
                  <ShippingIrregular>false</ShippingIrregular>
                  <ShippingPackage>PackageThickEnvelope</ShippingPackage>
                  <WeightMajor measurementSystem="English" unit="lbs">1</WeightMajor>
                  <WeightMinor measurementSystem="English" unit="oz">8</WeightMinor>
                </CalculatedShippingRate>
                <SellingManagerSalesRecordNumber>109</SellingManagerSalesRecordNumber>
                <ShipmentTrackingDetails>
                  <ShippingCarrierUsed>FedEx</ShippingCarrierUsed>
                  <ShipmentTrackingNumber>419328541735</ShipmentTrackingNumber>
                </ShipmentTrackingDetails>
              </ShippingDetails>
              <CreatedDate>2019-10-05T19:11:16.000Z</CreatedDate>
              <Item>
                <ItemID>123395219748</ItemID>
                <Site>US</Site>
                <Title>Anson Red 1972 Ferrari Dino 246 GT Die-Cast Metal 1/18 Scale NIB</Title>
                <ConditionID>1000</ConditionID>
                <ConditionDisplayName>New</ConditionDisplayName>
              </Item>
              <QuantityPurchased>1</QuantityPurchased>
              <Status>
                <PaymentHoldStatus>None</PaymentHoldStatus>
                <InquiryStatus>NotApplicable</InquiryStatus>
                <ReturnStatus>NotApplicable</ReturnStatus>
              </Status>
              <TransactionID>0</TransactionID>
              <TransactionPrice currencyID="USD">31.0</TransactionPrice>
              <ShippingServiceSelected>
                <ShippingPackageInfo>
                  <EstimatedDeliveryTimeMin>2019-10-15T07:00:00.000Z</EstimatedDeliveryTimeMin>
                  <EstimatedDeliveryTimeMax>2019-10-15T07:00:00.000Z</EstimatedDeliveryTimeMax>
                </ShippingPackageInfo>
              </ShippingServiceSelected>
              <TransactionSiteID>US</TransactionSiteID>
              <Platform>eBay</Platform>
              <Taxes>
                <TotalTaxAmount currencyID="USD">0.0</TotalTaxAmount>
                <TaxDetails>
                  <Imposition>SalesTax</Imposition>
                  <TaxDescription>SalesTax</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                  <TaxOnSubtotalAmount currencyID="USD">0.0</TaxOnSubtotalAmount>
                  <TaxOnShippingAmount currencyID="USD">0.0</TaxOnShippingAmount>
                  <TaxOnHandlingAmount currencyID="USD">0.0</TaxOnHandlingAmount>
                </TaxDetails>
                <TaxDetails>
                  <Imposition>WasteRecyclingFee</Imposition>
                  <TaxDescription>ElectronicWasteRecyclingFee</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                </TaxDetails>
              </Taxes>
              <ActualShippingCost currencyID="USD">10.79</ActualShippingCost>
              <ActualHandlingCost currencyID="USD">0.0</ActualHandlingCost>
              <OrderLineItemID>123395219748-0</OrderLineItemID>
              <ExtendedOrderID>123395219748-0!260000232745885</ExtendedOrderID>
              <eBayPlusTransaction>false</eBayPlusTransaction>
            </Transaction>
          </TransactionArray>
          <BuyerUserID>w***5</BuyerUserID>
          <PaidTime>2019-10-06T01:58:25.000Z</PaidTime>
          <ShippedTime>2019-10-08T17:01:00.000Z</ShippedTime>
          <IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled>
          <EIASToken>n==</EIASToken>
          <PaymentHoldStatus>None</PaymentHoldStatus>
          <IsMultiLegShipping>false</IsMultiLegShipping>
          <SellerUserID>r***9</SellerUserID>
          <SellerEIASToken>nY==</SellerEIASToken>
          <CancelStatus>NotApplicable</CancelStatus>
          <ExtendedOrderID>123395219748-0!260000232745885</ExtendedOrderID>
          <ContainseBayPlusTransaction>false</ContainseBayPlusTransaction>
        </Order>
        <Order>
          <OrderID>123406995532-0</OrderID>
          <OrderStatus>Completed</OrderStatus>
          <AdjustmentAmount currencyID="USD">0.0</AdjustmentAmount>
          <AmountPaid currencyID="USD">19.9</AmountPaid>
          <AmountSaved currencyID="USD">0.0</AmountSaved>
          <CheckoutStatus>
            <eBayPaymentStatus>NoPaymentFailure</eBayPaymentStatus>
            <LastModifiedTime>2019-10-18T17:30:27.000Z</LastModifiedTime>
            <PaymentMethod>CreditCard</PaymentMethod>
            <Status>Complete</Status>
            <IntegratedMerchantCreditCardEnabled>true</IntegratedMerchantCreditCardEnabled>
            <PaymentInstrument>CreditCard</PaymentInstrument>
          </CheckoutStatus>
          <ShippingDetails>
            <SalesTax>
              <SalesTaxPercent>0.0</SalesTaxPercent>
              <SalesTaxState></SalesTaxState>
              <ShippingIncludedInTax>false</ShippingIncludedInTax>
              <SalesTaxAmount currencyID="USD">0.0</SalesTaxAmount>
            </SalesTax>
            <ShippingServiceOptions>
              <ShippingService>USPSPriority</ShippingService>
              <ShippingServicePriority>1</ShippingServicePriority>
              <ExpeditedService>false</ExpeditedService>
              <ShippingTimeMin>1</ShippingTimeMin>
              <ShippingTimeMax>3</ShippingTimeMax>
            </ShippingServiceOptions>
            <ShippingServiceOptions>
              <ShippingService>Pickup</ShippingService>
              <ShippingServicePriority>2</ShippingServicePriority>
              <ExpeditedService>false</ExpeditedService>
            </ShippingServiceOptions>
            <SellingManagerSalesRecordNumber>110</SellingManagerSalesRecordNumber>
            <GetItFast>false</GetItFast>
          </ShippingDetails>
          <CreatedTime>2019-10-12T18:00:05.000Z</CreatedTime>
          <PaymentMethods>PayPal</PaymentMethods>
          <SellerEmail>r***l@g***l.com</SellerEmail>
          <ShippingAddress>
            <Name>j***z</Name>
            <Street1>1***8</Street1>
            <Street2></Street2>
            <CityName>h***g</CityName>
            <StateOrProvince>MS</StateOrProvince>
            <Country>US</Country>
            <CountryName>United States</CountryName>
            <Phone>6****6</Phone>
            <PostalCode>3***2-7**5</PostalCode>
            <AddressID>6****4</AddressID>
            <AddressOwner>eBay</AddressOwner>
            <ExternalAddressID></ExternalAddressID>
          </ShippingAddress>
          <ShippingServiceSelected>
            <ShippingService>USPSPriority</ShippingService>
            <ShippingServiceCost currencyID="USD">12.9</ShippingServiceCost>
          </ShippingServiceSelected>
          <Subtotal currencyID="USD">7.0</Subtotal>
          <Total currencyID="USD">19.9</Total>
          <TransactionArray>
            <Transaction>
              <Buyer>
                <Email>Invalid Request</Email>
                <UserFirstName>T***s</UserFirstName>
                <UserLastName>P***z</UserLastName>
              </Buyer>
              <ShippingDetails>
                <CalculatedShippingRate>
                  <OriginatingPostalCode>95125</OriginatingPostalCode>
                  <PackageDepth measurementSystem="English" unit="inches">5</PackageDepth>
                  <PackageLength measurementSystem="English" unit="inches">12</PackageLength>
                  <PackageWidth measurementSystem="English" unit="inches">7</PackageWidth>
                  <PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
                  <ShippingIrregular>false</ShippingIrregular>
                  <ShippingPackage>PackageThickEnvelope</ShippingPackage>
                  <WeightMajor measurementSystem="English" unit="lbs">1</WeightMajor>
                  <WeightMinor measurementSystem="English" unit="oz">8</WeightMinor>
                </CalculatedShippingRate>
                <SellingManagerSalesRecordNumber>110</SellingManagerSalesRecordNumber>
                <ShipmentTrackingDetails>
                  <ShippingCarrierUsed>USPS</ShippingCarrierUsed>
                  <ShipmentTrackingNumber>9405509699937977737731</ShipmentTrackingNumber>
                </ShipmentTrackingDetails>
              </ShippingDetails>
              <CreatedDate>2018-10-12T18:00:05.000Z</CreatedDate>
              <Item>
                <ItemID>123406995532</ItemID>
                <Site>US</Site>
                <Title>Mira Golden Line Collection 1:18 Diecast White 1964 1/2 Ford Mustang Convertible</Title>
                <ConditionID>1000</ConditionID>
                <ConditionDisplayName>New</ConditionDisplayName>
              </Item>
              <QuantityPurchased>1</QuantityPurchased>
              <Status>
                <PaymentHoldStatus>None</PaymentHoldStatus>
                <InquiryStatus>NotApplicable</InquiryStatus>
                <ReturnStatus>NotApplicable</ReturnStatus>
              </Status>
              <TransactionID>0</TransactionID>
              <TransactionPrice currencyID="USD">7.0</TransactionPrice>
              <ShippingServiceSelected>
                <ShippingPackageInfo>
                  <EstimatedDeliveryTimeMin>2019-10-19T07:00:00.000Z</EstimatedDeliveryTimeMin>
                  <EstimatedDeliveryTimeMax>2019-10-19T07:00:00.000Z</EstimatedDeliveryTimeMax>
                </ShippingPackageInfo>
              </ShippingServiceSelected>
              <TransactionSiteID>US</TransactionSiteID>
              <Platform>eBay</Platform>
              <Taxes>
                <TotalTaxAmount currencyID="USD">0.0</TotalTaxAmount>
                <TaxDetails>
                  <Imposition>SalesTax</Imposition>
                  <TaxDescription>SalesTax</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                  <TaxOnSubtotalAmount currencyID="USD">0.0</TaxOnSubtotalAmount>
                  <TaxOnShippingAmount currencyID="USD">0.0</TaxOnShippingAmount>
                  <TaxOnHandlingAmount currencyID="USD">0.0</TaxOnHandlingAmount>
                </TaxDetails>
                <TaxDetails>
                  <Imposition>WasteRecyclingFee</Imposition>
                  <TaxDescription>ElectronicWasteRecyclingFee</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                </TaxDetails>
              </Taxes>
              <ActualShippingCost currencyID="USD">12.9</ActualShippingCost>
              <ActualHandlingCost currencyID="USD">0.0</ActualHandlingCost>
              <OrderLineItemID>123406995532-0</OrderLineItemID>
              <ExtendedOrderID>123406995532-0!60000235703348</ExtendedOrderID>
              <eBayPlusTransaction>false</eBayPlusTransaction>
            </Transaction>
          </TransactionArray>
          <BuyerUserID>j***7</BuyerUserID>
          <PaidTime>2019-10-12T18:00:31.000Z</PaidTime>
          <ShippedTime>2019-10-16T18:06:22.000Z</ShippedTime>
          <IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled>
          <EIASToken>n==</EIASToken>
          <PaymentHoldStatus>None</PaymentHoldStatus>
          <IsMultiLegShipping>false</IsMultiLegShipping>
          <SellerUserID>r***9</SellerUserID>
          <SellerEIASToken>n==</SellerEIASToken>
          <CancelStatus>NotApplicable</CancelStatus>
          <ExtendedOrderID>123406995532-0!60000235703348</ExtendedOrderID>
          <ContainseBayPlusTransaction>false</ContainseBayPlusTransaction>
        </Order>
        <Order>
          <OrderID>123438071240-0</OrderID>
          <OrderStatus>Completed</OrderStatus>
          <AdjustmentAmount currencyID="USD">0.0</AdjustmentAmount>
          <AmountPaid currencyID="USD">20.75</AmountPaid>
          <AmountSaved currencyID="USD">0.0</AmountSaved>
          <CheckoutStatus>
            <eBayPaymentStatus>NoPaymentFailure</eBayPaymentStatus>
            <LastModifiedTime>2019-10-28T00:11:25.000Z</LastModifiedTime>
            <PaymentMethod>CreditCard</PaymentMethod>
            <Status>Complete</Status>
            <IntegratedMerchantCreditCardEnabled>true</IntegratedMerchantCreditCardEnabled>
            <PaymentInstrument>CreditCard</PaymentInstrument>
          </CheckoutStatus>
          <ShippingDetails>
            <SalesTax>
              <SalesTaxPercent>0.0</SalesTaxPercent>
              <SalesTaxState></SalesTaxState>
              <ShippingIncludedInTax>false</ShippingIncludedInTax>
              <SalesTaxAmount currencyID="USD">0.0</SalesTaxAmount>
            </SalesTax>
            <ShippingServiceOptions>
              <ShippingService>USPSPriority</ShippingService>
              <ShippingServicePriority>1</ShippingServicePriority>
              <ExpeditedService>false</ExpeditedService>
              <ShippingTimeMin>1</ShippingTimeMin>
              <ShippingTimeMax>3</ShippingTimeMax>
            </ShippingServiceOptions>
            <SellingManagerSalesRecordNumber>111</SellingManagerSalesRecordNumber>
            <GetItFast>false</GetItFast>
          </ShippingDetails>
          <CreatedTime>2019-10-24T18:33:17.000Z</CreatedTime>
          <PaymentMethods>PayPal</PaymentMethods>
          <SellerEmail>r*****@g*****.com</SellerEmail>
          <ShippingAddress>
            <Name>K***s</Name>
            <Street1>1***t</Street1>
            <Street2></Street2>
            <CityName>L***c</CityName>
            <StateOrProvince>CA</StateOrProvince>
            <Country>US</Country>
            <CountryName>United States</CountryName>
            <Phone>8***0</Phone>
            <PostalCode>9***6-3**9</PostalCode>
            <AddressID>4***8</AddressID>
            <AddressOwner>eBay</AddressOwner>
            <ExternalAddressID></ExternalAddressID>
          </ShippingAddress>
          <ShippingServiceSelected>
            <ShippingService>USPSPriority</ShippingService>
            <ShippingServiceCost currencyID="USD">8.75</ShippingServiceCost>
          </ShippingServiceSelected>
          <Subtotal currencyID="USD">12.0</Subtotal>
          <Total currencyID="USD">20.75</Total>
          <TransactionArray>
            <Transaction>
              <Buyer>
                <Email>k***s@v***n.net</Email>
                <UserFirstName>K***m</UserFirstName>
                <UserLastName>T***s</UserLastName>
              </Buyer>
              <ShippingDetails>
                <CalculatedShippingRate>
                  <OriginatingPostalCode>95391</OriginatingPostalCode>
                  <PackageDepth measurementSystem="English" unit="inches">4</PackageDepth>
                  <PackageLength measurementSystem="English" unit="inches">10</PackageLength>
                  <PackageWidth measurementSystem="English" unit="inches">10</PackageWidth>
                  <PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
                  <ShippingIrregular>false</ShippingIrregular>
                  <ShippingPackage>PackageThickEnvelope</ShippingPackage>
                  <WeightMajor measurementSystem="English" unit="lbs">2</WeightMajor>
                  <WeightMinor measurementSystem="English" unit="oz">0</WeightMinor>
                </CalculatedShippingRate>
                <SellingManagerSalesRecordNumber>111</SellingManagerSalesRecordNumber>
                <ShipmentTrackingDetails>
                  <ShippingCarrierUsed>USPS</ShippingCarrierUsed>
                  <ShipmentTrackingNumber>9405509699937995873329</ShipmentTrackingNumber>
                </ShipmentTrackingDetails>
              </ShippingDetails>
              <CreatedDate>2019-10-24T18:33:17.000Z</CreatedDate>
              <Item>
                <ItemID>123438071240</ItemID>
                <Site>US</Site>
                <Title>Jonathon Byron Floating Swans 3-D Hand-Painted Porcelain Collector Plate</Title>
                <ConditionID>1000</ConditionID>
                <ConditionDisplayName>New</ConditionDisplayName>
              </Item>
              <QuantityPurchased>1</QuantityPurchased>
              <Status>
                <PaymentHoldStatus>None</PaymentHoldStatus>
                <InquiryStatus>NotApplicable</InquiryStatus>
                <ReturnStatus>NotApplicable</ReturnStatus>
              </Status>
              <TransactionID>0</TransactionID>
              <TransactionPrice currencyID="USD">12.0</TransactionPrice>
              <ShippingServiceSelected>
                <ShippingPackageInfo>
                  <EstimatedDeliveryTimeMin>2019-10-29T07:00:00.000Z</EstimatedDeliveryTimeMin>
                  <EstimatedDeliveryTimeMax>2019-10-29T07:00:00.000Z</EstimatedDeliveryTimeMax>
                </ShippingPackageInfo>
              </ShippingServiceSelected>
              <TransactionSiteID>US</TransactionSiteID>
              <Platform>eBay</Platform>
              <Taxes>
                <TotalTaxAmount currencyID="USD">0.0</TotalTaxAmount>
                <TaxDetails>
                  <Imposition>SalesTax</Imposition>
                  <TaxDescription>SalesTax</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                  <TaxOnSubtotalAmount currencyID="USD">0.0</TaxOnSubtotalAmount>
                  <TaxOnShippingAmount currencyID="USD">0.0</TaxOnShippingAmount>
                  <TaxOnHandlingAmount currencyID="USD">0.0</TaxOnHandlingAmount>
                </TaxDetails>
                <TaxDetails>
                  <Imposition>WasteRecyclingFee</Imposition>
                  <TaxDescription>ElectronicWasteRecyclingFee</TaxDescription>
                  <TaxAmount currencyID="USD">0.0</TaxAmount>
                </TaxDetails>
              </Taxes>
              <ActualShippingCost currencyID="USD">8.75</ActualShippingCost>
              <ActualHandlingCost currencyID="USD">0.0</ActualHandlingCost>
              <OrderLineItemID>123438071240-0</OrderLineItemID>
              <ExtendedOrderID>123438071240-0!240000241528240</ExtendedOrderID>
              <eBayPlusTransaction>false</eBayPlusTransaction>
            </Transaction>
          </TransactionArray>
          <BuyerUserID>k***y</BuyerUserID>
          <PaidTime>2019-10-24T20:09:09.000Z</PaidTime>
          <ShippedTime>2019-10-25T16:27:09.000Z</ShippedTime>
          <IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled>
          <EIASToken>n==</EIASToken>
          <PaymentHoldStatus>None</PaymentHoldStatus>
          <IsMultiLegShipping>false</IsMultiLegShipping>
          <SellerUserID>r***9</SellerUserID>
          <SellerEIASToken>n==</SellerEIASToken>
          <CancelStatus>NotApplicable</CancelStatus>
          <ExtendedOrderID>123438071240-0!240000241528240</ExtendedOrderID>
          <ContainseBayPlusTransaction>false</ContainseBayPlusTransaction>
        </Order>
      </OrderArray>
      <OrdersPerPage>100</OrdersPerPage>
      <PageNumber>1</PageNumber>
      <ReturnedOrderCountActual>3</ReturnedOrderCountActual>
    </GetOrdersResponse>

    Ich bin für jeden Tipp dankbar.

    Gruß
    Sven

    Dienstag, 25. Februar 2020 15:43

Antworten

  • Hi Sven,
    nachfolgend eine schnell erstellte Lösung. Schade, dass du kein VB.NET nutzt. Da ist die LinQ-Unterstützung für XML am Klassen besser.

    using System;
    using System.Linq;
    using System.Xml.Linq;
    
    namespace ConsoleApp1
    {
      class Program24
      {
        static void Main(string[] args)
        {
          try
          {
            (new Demo()).Execute();
          }
          catch (Exception ex) { Console.WriteLine(ex.ToString()); }
          Console.WriteLine("Continue enter key");
          Console.ReadKey();
        }
    
        internal class Demo
        {
          internal void Execute()
          {
            XElement xe0 = XElement.Load("Program24.xml");
            foreach (var order in xe0.Descendants().Where((o) => o.Name.LocalName == "Order"))
            {
              string OrderID = order.Descendants().Where((oi) => oi.Name.LocalName == "OrderID").FirstOrDefault().Value;
              string Street1 = order.Descendants().Where((oi) => oi.Name.LocalName == "Street1").FirstOrDefault().Value;
              string Total = order.Descendants().Where((oi) => oi.Name.LocalName == "Total").FirstOrDefault().Value;
              Console.WriteLine($"OrderID: {OrderID}, Street1: {Street1}, Total: {Total}");
            }
          }
        }
      }
    }


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Mittwoch, 26. Februar 2020 07:56

Alle Antworten

  • Hi Sven,
    die Frage ist: "Welche Daten benötigst Du?".

    Lade die Daten in ein XElement und hole Dir die gewünschten Knoten und die Attributwerte bzw. die Werte dieser Knoten. Hier mal eine WPF Demo, die mit VS 2019 erstellt werden kann.

    XAML:

    <Window x:Class="Window85"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:WpfApp1"
            mc:Ignorable="d"
            Title="Window85" Height="450" Width="800">
      <Window.DataContext>
        <local:Window85VM/>
      </Window.DataContext>
      <Grid>
        <TreeView ItemsSource="{Binding View}">
          <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type local:Window85Data}"
                                      ItemsSource="{Binding Childs}">
              <TextBlock Text="{Binding Value}"/>
            </HierarchicalDataTemplate>
          </TreeView.Resources>
        </TreeView>
      </Grid>
    </Window>
    

    ViewModel und Data Klasse:

    Imports System.Collections.ObjectModel
    Imports System.ComponentModel
    
    Public Class Window85VM
    
      Private cvs As New CollectionViewSource
      Public ReadOnly Property View As ICollectionView
        Get
          cvs.Source = LoadCollection(XElement.Load("Window85.xml"))
          Return cvs.View
        End Get
      End Property
    
      Private Function LoadCollection(xe1 As XElement) As ObservableCollection(Of Window85Data)
        Dim l As New ObservableCollection(Of Window85Data)
        For Each xe2 In xe1.Elements
          l.Add(New Window85Data With {.Value = $"{xe2.Name.LocalName}", .Childs = LoadCollection(xe2)})
        Next
        Return l
      End Function
    
    End Class
    
    Public Class Window85Data
      Public Property Value As String
      Public Property Childs As ObservableCollection(Of Window85Data)
    End Class


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Dienstag, 25. Februar 2020 16:14
  • Hallo Peter,

    schön das Du mir wieder hilfst.

    Für den Anfang um zu verstehen wie das funktioniert würde es mir helfen wenn Du mir ein Beispiel jeweils für die folgenden 3 Elemente geben würdest. Bitte das Beispiel in C# wenn möglich erstellen.

    GetOrdersResponse --> OrderArray --> Order --> OrderID
    GetOrdersResponse --> OrderArray --> Order --> ShippingAddress --> Street1
    GetOrdersResponse --> OrderArray --> Order --> <Total currencyID="USD">41.79</Total>

    Die Daten habe ich aus meinem ersten Post (XML Beispiel).

    Wünsche Dir eine schöne Woche.

    Gruß
    Sven

    Mittwoch, 26. Februar 2020 01:05
  • Hi Sven,
    nachfolgend eine schnell erstellte Lösung. Schade, dass du kein VB.NET nutzt. Da ist die LinQ-Unterstützung für XML am Klassen besser.

    using System;
    using System.Linq;
    using System.Xml.Linq;
    
    namespace ConsoleApp1
    {
      class Program24
      {
        static void Main(string[] args)
        {
          try
          {
            (new Demo()).Execute();
          }
          catch (Exception ex) { Console.WriteLine(ex.ToString()); }
          Console.WriteLine("Continue enter key");
          Console.ReadKey();
        }
    
        internal class Demo
        {
          internal void Execute()
          {
            XElement xe0 = XElement.Load("Program24.xml");
            foreach (var order in xe0.Descendants().Where((o) => o.Name.LocalName == "Order"))
            {
              string OrderID = order.Descendants().Where((oi) => oi.Name.LocalName == "OrderID").FirstOrDefault().Value;
              string Street1 = order.Descendants().Where((oi) => oi.Name.LocalName == "Street1").FirstOrDefault().Value;
              string Total = order.Descendants().Where((oi) => oi.Name.LocalName == "Total").FirstOrDefault().Value;
              Console.WriteLine($"OrderID: {OrderID}, Street1: {Street1}, Total: {Total}");
            }
          }
        }
      }
    }


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Mittwoch, 26. Februar 2020 07:56
  • Hi Peter,

    vielen vielen Dank. Ohne Deine Hilfe hätte ich es nicht geschafft. Ich antworte erst jetzt da ich kein Internet hatte die letzten Tage.

    Was für Bücher hast Du gelesen die ich unbedingt in der Entwicklung von MS Windows Apps oder auch für ASP.NET CORE gelesen haben sollte.

    Gruß
    Sven

    Montag, 2. März 2020 19:47
  • Hi Sven,
    ich selbst favorisiere 3 Dinge:

    1. Grundlagen der Programmierung muss man erlernen (Werkzeuge wie Verzweigungen, Schleifen, Deklarationen usw. unabhängig von der Programmiersprache) und das am besten als Teil eines Fach- oder Hochschulstudiums. Zusätzlich ist eine Ausbildung zu den technischen Grundlagen wie Arbeit einer CPU, Grafik usw. sehr hilfreich, insbesondere, um multi-thjreading zu verstehen.

    2. Selbständiges Erlernen und ständiges Erweitern der zu nutzenden Techniken und Werkzeuge (z.B. Framework, Visual Studio, TFS, DevOps und auch Grundlagen zu den Systemen wie Betriebssystem, Netzwerk, Kommunikationstechnologien usw.). Wichtig ist bezüglich dieser Foren das Framework. Und da sollte jeder die Programming Microsoft Visual Basic .NET (Core Reference) durcharbeiten. Das Durcharbeiten dieser 1600 Seiten erfordert aber mindestens 3 Monate Vollzeit-Arbeit. Hinzu kommt das gewaltige Wissen im Internet, insbesondere die MSDN. Spaß machen auch die vielen kleine Crash-Bücher, die man nebenbei z.B. unterwegs lesen kann.

    3. Lösung konkreter Aufgabenstellungen, d.h. Erstellung vollständiger Projekte, beginnend mit Problem- und Aufgabenanalyse, Erarbeitung von Algorithmen, Datenstrukturen, Projektgliederung, Tests usw.


    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    Dienstag, 3. März 2020 05:50