Differences between selectNodes and selectSingleNode

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.