XmlText

Текстовый элемент XML-документа.

Пример программы, создающей XML-документ

// Создать новый документ XML в памяти.

XmlDocument doc = new XmlDocument ();

// Заполнить документ корневым элементом по имени <recipe>.

XmlElement recipe = doc.CreateElement("recipe");

// Установим атрибуты

recipe.SetAttribute("name", "хлеб");

// Создадим подэлемент по имени <title>

XmlElement title = doc.CreateElement("title");

title.InnerText = "Простой хлеб";

// Создадим подэлементы <ingredient>

XmlElement ingredient0 = doc.CreateElement("ingredient");

ingredient0.InnerText = "Мука";

ingredient0.SetAttribute("amount", "3");

ingredient0.SetAttribute("unit", "стакан");

XmlElement ingredient1 = doc.CreateElement("ingredient");

ingredient1.InnerText = "Дрожжи";

ingredient1.SetAttribute("amount", "0.25");

ingredient1.SetAttribute("unit", "грамм");

// Создадим комментарий

XmlComment comment = doc.CreateComment("This is comment");

// Добавим подэлементы в элемент <recipe>

recipe.AppendChild(title);

recipe.AppendChild(ingredient0);

recipe.AppendChild(ingredient1);

recipe.AppendChild(comment);

// Вставим полный XML в объект XmlDocument и сохраним в файле

doc.AppendChild(recipe);

doc.Save ("Recipe.xml");


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: