How to load the xml string in the code below to manage UIB databases that are bound to XPath XML?

Each sample I saw uses static XML in the xmldataprovider source, which is then used to manage UI data using XPath binding. The idea is to edit dynamic XML (a structure known to the developer at the time of coding) using the WPF interface.

Has anyone found a way to load a dynamic xml string (e.g. load it from a file at runtime) and then use that xml string as the source of the XmlDataprovider?

Code snippets will be great.

Update. To make it more understandable, let's say I want to load the xml string that I received from the web service call. I know the xml structure. Therefore, I bind it to the WPF controls in the WPF window. How to do it? All samples over the Internet define all XML inside the XAML code in the XmlDataProvider node. This is not what I am looking for. I want to use the xml string in the code to bind to user interface controls.

+3
source share
2 answers

Here is the code I used to load the XML file from disk and bind it to a TreeView. I removed some of the usual tests for brevity. The XML in the example is an OPML file.

XmlDataProvider provider = new XmlDataProvider();

if (provider != null)
{
  System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
  doc.Load(fileName);
  provider.Document = doc;
  provider.XPath = "/opml/body/outline";
  FeedListTreeView.DataContext = provider;
}
+2
source

-, XML XML-. xmlDataProvider XMLDocument, .

, , .

, :

1. Get XML from webservice
2. Convert XML String to XML Document
3. Set the XMLDataProvider.Document value to your XML Document
4. Bind that to your controls
+1

Source: https://habr.com/ru/post/1696843/


All Articles