Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I read a field from an Xml stream without deserializing it?

0
10 Posted

How can I read a field from an Xml stream without deserializing it?

0
10

XPath can do the job.. This is an example where we read the town name (Xml element) )and the state attribute from the Xml file: XmlDocument document = new XmlDocument(); document.Load(“town.xml”); //Select an element string _TownName = document.SelectSingleNode(“//city/townname”).InnerText; //Select an attribute string _State = document.SelectSingleNode(“//city”).Attributes[“state”].InnerText; MessageBox.Show(_TownName + ” is in ” + _State); This is an example where we read an application setting from a web config file. XmlDocument configDocument = new XmlDocument(); configDocument.Load(“web.config”); // Add the namespace with .Net web.config XmlNamespaceManager nsmgr = new XmlNamespaceManager(configDocument.NameTable); nsmgr.AddNamespace(“ms”, “http://schemas.microsoft.com/.NetConfiguration/v2.0”); string appSetting = configDocument.SelectSingleNode( “/ms:configuration/ms:appSettings/ms:add[@key=’DatabaseName’]”, nsmgr).Attributes[“value”].InnerText; The orignal config file:

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123