Home > Net >  C # XML additional attributes, how
C # XML additional attributes, how

Time:02-06

 
//initializes the object
XDocument xdoc=new XDocument ();
//initialize the top node object
XElement Pers=new XElement (" top node ");
//the initial changes the node object
XElement p=new XElement (" child ");

//add attribute
P.A dd (new XAttribute (" name ", "little red"));
P.A dd (new XAttribute (" age ", "68"));

Pers. Add (p);
Xdoc. Add (Pers);
Xdoc. Save (" 111. XML ");


 
<? The XML version="1.0" encoding="utf-8"?>


I'd like to add a new attribute, name xiao Ming age 58
If I direct p.A dd (new XAttribute (" name ", "Ming")); Can indeed, but it is covered within the original file, is not what I want, the additional effect of advice on how to get

CodePudding user response:

First you read the original file in, and then in the Add?

CodePudding user response:

<? The XML version="1.0" encoding="utf-8"?>

-



To achieve this effect?

CodePudding user response:

: so you're going to add child nodes, rather than the attributes,,,,
//the initial changes the node object

//add attribute
P1. The Add (new XAttribute (" name ", "little red 1"));
P1. The Add (new XAttribute (" age ", "681"));

Pers. Add (p1);
  •  Tags:  
  • C#
  • Related