The depressing selectnodes method of XML

Source: Internet
Author: User

In the selectnodes (XPath, namespace) Method
Whether xmldoc. selectnodes (XPath, namespace) // assume that xmldoc is the root node,Queries under the entire document
Or xmldoc. childnodes [I]. selectnodes (XPath, namespace )//Query under a node

The results of the two queries are the same: All documents that comply with the XPath syntax conditions are checked out.
In fact, all we need is the result that meets the XPath syntax under a node.


After a complete query and research solution...
Xmldoc. childnodes [I]. Clone (). selectnodes (XPath, namespace) can be used to solve the problem.
After cloning a node, You can query it from the cloned node to find the desired result.

But another problem arises. Since the query result is cloned, the original xmldoc will not change even if the result node is changed.

The temporary Method for associating changes is to traverse xmldoc. childnodes [I], locate the nodes that meet the conditions, and replace the result nodes.

Summary:
Now that we have to traverse the replacement results, the previous clone node query seems a little redundant. The first direct traversal is not enough.

Conclusion:
Is the node. selectnodes method under a certain node significant?
Selectnodes can only be used in the entire XML document!

 

Edit the final answer:

I encountered it again today. Record it. The correct method is:
Subnode. selectnodes ("Descendant: node name", namespace)

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.