Ihave an xml file sample.xml
i need to display number from above xml file in a listview named _listView which contain version column named _version,can you give me the optimized code required to do that task
Ihave an xml file sample.xml
i need to display number from above xml file in a listview named _listView which contain version column named _version,can you give me the optimized code required to do that task
using System.Xml.Linq;
string xml = ...
string version = XElement.Parse(xml).Element("ManagedObject").Attribute("version").Value;
There is an example on using a listview here
How about:
XNamespace ns = "http://tempuri.org/SpoDataSchema.xsd";
string version = (string)XDocument.Load("sample.xml").Root
.Element(ns + "ManagedObject").Element(ns + "version");
Or in 2.0:
XmlDocument doc = new XmlDocument();
doc.Load("sample.xml");
XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
nsmgr.AddNamespace("spo", "http://tempuri.org/SpoDataSchema.xsd");
XmlNode node = doc.SelectSingleNode(
"/spo:SpoDataSchema/spo:ManagedObject/spo:version", nsmgr);
string version = node == null ? null : node.InnerText;
Then display version
however you want. For displaying in a ListView
:
using (Form form = new Form())
using (ListView lv = new ListView())
{
lv.Dock = DockStyle.Fill;
lv.View = View.Details;
lv.Columns.Add("Version");
lv.Items.Add(version);
form.Controls.Add(lv);
form.ShowDialog();
}