Вставьте новый узел XML с помощью LINQ - PullRequest
2 голосов
/ 13 марта 2011

XML:

<Questions>
   <Question>
      <Id>1</Id>
      <Text>aaa</Text>
      <Reserver />
   </Question>
   <Question>
      <Id>2</Id>
      <Text>bbb</Text>
      <Reserver />
 </Question>
</Questions>

Как вставить новый вопрос, используя LINQ, например:

<Question>
      <Id>3</Id>
      <Text>ccc</Text>
      <Reserver />
 </Question>

Ответы [ 2 ]

1 голос
/ 13 марта 2011
XDocument doc = XDocument.Parse("<Questions>...</Questions>");
doc.Root.Add(
    new XElement("Question",
        new XElement("Id", 3),
        new XElement("Text", "ccc"),
        new XElement("Reserver"))
    );
0 голосов
/ 13 марта 2011

Вы можете создать новый элемент, подобный этому:

var newElem = new XElement("Question",
    new XElement("Id", 3),
    ...
);
xdoc.Root.Add(newElem);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...