Today, we can see a difference between selectNodes and selectSingleNode on the Internet.
I was surprised to see it today because I didn't care much about it before. Copy it for everyone to learn!
The most important difference mentioned in this article is the changes after the use of operations.
Selectnodes: differences between selectNodes and ChildNodes in obtaining XML content Arrays
When we use XML to query or change data, we need to pay attention to the usage of two very similar but different results, as shown below:
1: XmlDocument doc = new XmlDocument ();
2: Doc. loadXml (strXml );
3: XmlNodeList xnlListOne = doc. selectNodes ("// Nodes/Node ");
4: XmlNodeList xnlListTwo = doc. selectSingleNode ("// Nodes"). ChildNodes;
At first glance, both xnlListOne and xnlListTwo obtain the Node array in the current Xml document. If we do not change this Xml document, there is no difference between the two, however, once we add or delete the Node nodes in the subsequent operations, the situation will be different. After the change, when we use the previously obtained xnlListOne and xnlListTwo for traversal, we will find that the former will not change, and the latter will be updated in real time based on changes in the document content!
This feature will also appear in the scripts on the front-end page. For example, when div Nesting is used to obtain its nested sub-div, it will also be updated in real time by using ChildNodes, this feature is because they all operate their content through pointers. It should be accompanied by this traversal operation internally, and the obtained result array is the result of a calculation, we have opened up new memory for storage, so it will not be affected. Of course, we can also use this feature for some special features.