Delete a specified node in XML

Source: Internet
Author: User

Today, C # is used to read the configuration file and delete the specified node. This is simple, but it will make a mistake if you don't pay attention to it. Come and share your experience.

Public void remove (videosource)
{

String innertext = videosource. typeid + videosource. Name + videosource. thumbpath + videosource. videopath;

Xmldocument xml = new xmldocument ();

XML. Load (system. Windows. Forms. application. startuppath + "/XML/videosourcexml. xml ");

// Obtain all the subnodes under the first videosources

Xmlnodelist = xml. selectsinglenode ("videosources"). childnodes;

Foreach (xmlnode item in xmlnodelist)

{

If (item. innertext = innertext)

{

// PS: If you use XML. removechild (item), The removed node is definitely not a child node of XML.

XML. selectsinglenode ("videosources"). removechild (item );

// Item. removeall (); All subnodes under item can be deleted.

Break;

}

}

XML. Save (system. Windows. Forms. application. startuppath + "/XML/videosourcexml. xml ");

}

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.