hallo,
möchte mich entschuldigen wen das thema schon gibt aber ich hab leider nix gefunden und muss morgen das programm abgeben und finde keine antwort wie ich auch einer xml datei ChildNodes übergebe in windowsForms
das ist mein programm halb fertig
also ich habe kontinente und lander kontinente kan ich übergeben in eine groupBox dan kan ich die länder übergeben
jetzt muss ich die ChildNodes von den Ländern übergeben klappt leider nicht weil ich nicht so viel anhnung hab.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52:
| using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace LeanderErmieteln { public partial class Form1 : Form { DataModel dm = new DataModel(); const string PFADUEBERSICHT = "..\\..\\..\\LaenderInfo\\Kontinente.xml"; string dateipfad = "..\\..\\..\\LaenderInfo\\";
public Form1() { InitializeComponent(); string[] Kontinent = dm.alleErstenKnoten(PFADUEBERSICHT); comboKontinent.Items.AddRange(Kontinent);
}
private void comboKontinent_SelectedIndexChanged(object sender, EventArgs e) { comboLaender.Items.Clear(); string pfad = dateipfad + comboKontinent.SelectedItem + ".xml"; string[] Laender = dm.alleErstenKnoten(pfad); comboLaender.Items.AddRange(Laender); }
private void comboInfo_TextChanged(object sender, EventArgs e) { XmlDocument doc = new XmlDocument(); doc.Load("..\\..\\..\\LaenderInfo\\");
XmlNode node1 = doc.SelectSingleNode("/Pakistan//Hauptstadt"); MessageBox.Show(node1.InnerText); }
}
} |
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56:
| using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Xml;
namespace LeanderErmieteln { class DataModel { private XmlDocument document = new XmlDocument(); private XmlNodeList alleknoten;
public string[] alleErstenKnoten(string pfadname)
{ string[] alle = null;
document.Load(pfadname);
XmlNode root = document.DocumentElement;
alleknoten = root.ChildNodes;
alle = new string[alleknoten.Count]; for (int i = 0; i < alleknoten.Count; i++) { alle[i] = alleknoten[i].Name; }
return alle; }
public string[] getInformation(int knotennummer)
{ string[] info = null;
XmlNodeList infoliste = alleknoten[knotennummer].ChildNodes; info = new string[infoliste.Count]; for (int i = 0; i < infoliste.Count; i++) info[i] = infoliste[i].InnerText;
return info;
}
} } |
Das ist nur ein Teil meiner xml ^^
XML-Daten
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| <Asien Flaeche ="44614 Mill qkm"> <Pakistan> <Hauptstadt>Moskow</Hauptstadt> <Einwohner> 172</Einwohner> <Einwohnerqkm>190</Einwohnerqkm> <qkm> 880 000</qkm> <Bruttoinlandsprodukt>424 Mrd</Bruttoinlandsprodukt> <Prokopfeinkommen> 2700</Prokopfeinkommen> <Geburtenrate>4</Geburtenrate> <Religion>Islam</Religion> <Hochschulabsolventen>0,54</Hochschulabsolventen> </Pakistan> |
Moderiert von
Christian S.: C#-Tags hinzugefügt
Moderiert von
Christian S.: XML-Tags hinzugefügt