简体   繁体   中英

How to insert the new element on XMLNode in C#

I am trying to insert a new element into the XmlNode in C# code,

How to insert the <delimiter>@#<delimiter> element in inside the "/TestBooks/template/field" root. (Screenshot1) enter image description here

Inside the <field> element, i need to insert the <delimiter> element, based on id element <Id>11-09-2020-505</Id> . (Screenshot2) enter image description here

First of all you really shouldn't use pictures in questions -- we are taking the time to type you an answer you can take the time to use copy and paste and format your questions.

I'd like to answer your questions but I'm concerned about the questions because it implies that you are adding in markers to aid in the parsing of the data. You really shouldn't need to parse XML.

There are many great parsers of XML including one built into C# you should not roll your own.

In the XML standard the order of the children not defined. If you put a child as the "first" child, there is no reason to expect that a parser would list it as first.

(To have order in children you should just add an order attribute)

Because of these reason it should not matter where in the list of children you add the child.

So we can tell you how to add a child but we can't "put it in a specific spot" since children don't have an order.

In summary, it is not possible to do what you ask.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM