LINQ to XML: Modify node content

Source: Internet
Author: User

Xdocument = new xdocument (<br/> New xelement ("bookpays", firstpays = <br/> New xelement ("bookpays ", <br/> New xcomment ("this is a new author. "), <br/> New xattribute (" type "," author "), <br/> New xelement (" firstname "," Joe "), <br/> New xelement ("lastname", "rattz"); </P> <p> console. writeline ("before updating nodes:"); <br/> console. writeline (xdocument); </P> <p> // now, lets update an element, a comment, and a text node. <br/> firstparticipant ipant. element ("firstname "). value = "Joey"; <br/> firstparticipant ipant. nodes (). oftype <xcomment> (). single (). value = <br/> "author of pro LINQ: Language Integrated Query in C #2008. "; <br/> (xelement) firstparticipant ipant. element ("firstname "). nextnode) <br/>. nodes (). oftype <xtext> (). single (). value = "rattz, Jr. "; </P> <p> console. writeline ("after updating nodes:"); <br/> console. writeline (xdocument ); 

 

Output

 

Before updating nodes: <br/> <bookpays> <br/> <bookpays type = "author"> <br/> <! -- This is a new author. --> <br/> <firstname> Joe </firstname> <br/> <lastname> rattz </lastname> <br/> </bookparticipant ipant> <br/> </ bookparticipant ipants> <br/> after updating nodes: <br/> <bookpays> <br/> <bookpays type = "author"> <br/> <! -- Author of pro LINQ: Language Integrated Query in C #2008. --> <br/> <firstname> Joey </firstname> <br/> <lastname> rattz, Jr. </lastname> <br/> </bookparticipant ipant> <br/> </bookparticipant ipants> 

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.