I’m a big fan of using XML to select nodes from a set of XML. However, the XPath classes aren’t available to Windows Store Developers as yet, so an alternative method of getting nodes easily, without needing to understand their address at development time is very valuable to me.
Linq tutorials tend to need an understanding of the makeup of the document prior to coding, but if I have a document where a node is buried in the schema, for example something like //root/TimeSeries/Days/Data/Close/Adjusted, and I just want those values, XPath is very useful because I can use the same code to get those nodes, or nodes such as //root/TimeSeries/Days/Date or something in a different part of the XML tree.
The System.Xml.Linq.XDocument has a useful ‘Descendants’ method that allows me to get all the nodes that match a particular name. It’s not as powerful as XPath, but it’s still pretty good.
So, for example, I can do something like this:
string strData = await client.getPriceHistoryAsStringAsync("MSFT", "1/1/2013", "2/1/2013");
StringReader sRead = new StringReader(strData);
XDocument xmlDoc = XDocument.Load(sRead);
var closing = from node in xmlDoc.Descendants("Close") select node.Value;
This will give me a List<> containing the values of all the nodes that match “Close” in my XML Data, a snippet of which looks like this:
So regardless of where the <Close> values are in the schema, I get a list<> of their values with the above code, making it easy for me to chart them, and making it really easy to write a function that is data agnostic, where I can pass the node that I want to get data into the function, and use that to return the List<> of the data, like this:
private List<string> getData(string nodeName, XDocument xmlDoc)
var lReturn = from node in xmlDoc.Descendants(nodeName) select node.Value;
I hope this is useful to you! :)
je n'arrive pas à changer la couleur de trame dans dans le lecteur windows média
Peut-être essayer cela ?