Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Empfohlene Antworten

Veröffentlicht

Moinsen ihr alle,

ich beiß hier gleich in meinen Tisch!!

Ich möchte eigentlich nichts anderes, als eine xml datei die ich bekomme auslesen und dann die entsprechenden werte in einer sql datenbank ablegen.

Nun scheitere ich grade schon am auslesen der ... Daten!

Kann mir mal kurz einer sagen wo mein Denkfehler ist???

 XmlDocument document = new XmlDocument();

            document.Load(@"E:\test.xml");


            XmlNode root = document.DocumentElement;

            XmlNode node = root.SelectSingleNode("//envelope");


            Console.WriteLine("timestamp: {0}", node["timestamp"].InnerText);

            Console.WriteLine("transaction: {0}", node["transaction"].InnerText);

            Console.WriteLine("order_type: {0}", node["order_type"].InnerText);


            Console.ReadKey(true);

Das ist nur ein kurzer Test um zu schauen ob er die Werte richtig ausließt...

Ich bekomme aber sofort die Meldung

"der objektverweis wurde nicht auf eine objektinstanz festgelegt"

Ich würde mich über ne kleine Info wirklich freuen!

Doc

Hallo DocSpencer!

Wenn du das direkt in eine Staging-Tabelle laden möchtest und Zugriff auf die SQL Server Integration Services hast, kann ich dir nur wärmstens den Data Flow Task ans Herz legen.

Da kannst du jedem Element bzw. dem Wert eine Spalte zuweisen und das SSIS-Paket mappt alles automatisch.

Haltepunkte, an welcher Stelle die Exception geworfen wird, hast du vermutlich schon gesetzt, oder?

Gruß, Goulasz

  • Autor

Ich habe ganz vergessen die xml dazu zu packen...

Sorry dafür!

<?xml version="1.0" encoding="UTF-8"?>

<envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema_instance" xsi:noNamespaceSchemaLocation="actual_shipped.xsd">

  <actual_shipped order_id="12345678">

    <timestamp>2015_05_10T14:27:49</timestamp>

    <transaction>Shipment</transaction>

    <order_type>Neuversand mit Konfiguration</order_type>

    <terminal_id>1234567</terminal_id>

    <client>bla</client>

    <ship_to_address>

      <name>Max Mustermann</name>

      <contact>Max Mustermann</contact>

      <street>Musterstr. 5</street>

      <postal_code>12345</postal_code>

      <city>Musterstadt</city>

      <country>DE</country>

    </ship_to_address>

    <shipping_date>2015_05_10T14:27:49</shipping_date>

  </actual_shipped>

</envelope>

Dein root node ist envelope. Du müsstest //actual_shipped auswählen.

Hier mal ne LINQ Variante. Der Vorteil hier ist, dass dir die IDE ein wenig bei der Formulierung der queries hilft.


using System;

using System.Linq;

using System.Xml.Linq;


namespace LoadXml

{

	class MainClass

	{

		static string testXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + 

					"<envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema_instance\" xsi:noNamespaceSchemaLocation=\"actual_shipped.xsd\">" +

					"  <actual_shipped order_id=\"12345678\">" +

					"    <timestamp>2015_05_10T14:27:49</timestamp>" +

					"    <transaction>Shipment</transaction>" +

					"    <order_type>Neuversand mit Konfiguration</order_type>" +

					"    <terminal_id>1234567</terminal_id>" +

					"    <client>bla</client>" +

					"    <ship_to_address>" +

					"      <name>Max Mustermann</name>" +

					"      <contact>Max Mustermann</contact>" +

					"      <street>Musterstr. 5</street>" +

					"      <postal_code>12345</postal_code>" +

					"      <city>Musterstadt</city>" +

					"      <country>DE</country>" +

					"    </ship_to_address>" +

					"    <shipping_date>2015_05_10T14:27:49</shipping_date>" +

					"  </actual_shipped>" +

				"</envelope>";


		public static void Main (string[] args)

		{

			var d = XDocument.Parse (testXml);

			var result = from x in d.Descendants ("actual_shipped")

			select new 

				{ 

					TimeStamp = x.Element ("timestamp").Value,

					Transaction = x.Element ("transaction").Value,

					OrderType = x.Element ("order_type").Value

				};



			foreach (var r in result) {

				Console.WriteLine ("timestamp: {0}", r.TimeStamp);

				Console.WriteLine ("transaction: {0}", r.Transaction);

				Console.WriteLine ("order_type: {0}", r.OrderType);

			}

		}

	}

}

Man könnte sich auch so etwas vorstellen : C# Load XML using XLINQ (LINQ to XML)

Erstelle ein Konto oder melde dich an, um einen Kommentar zu schreiben.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.