Формирование XML - C# (197230)
Формулировка задачи:
Доброго времени суток!!!
Возник вопрос
Использую данный код
и получаю файл
Подскажите пожалуйста как получить такой xml - файл
XElement xmlDoc = new XElement("Trucks", new XAttribute("id", ""), new XAttribute("Port", ""), new XAttribute("ip", "")); for (int v = 0; v < 4; v++) { xmlDoc.Add(new XElement("truck", new XElement("hard"), new XElement("tree", new XElement("M-16")))); for (int i = 0; i < 4; i++) { xmlDoc.LastNode.AddAfterSelf(new XElement("G-4")); } }
<?xml version="1.0" encoding="utf-8" ?> - <Trucks id="" Port="" ip=""> - <truck> <hard /> - <tree> <M-16 /> </tree> </truck> <G-4 /> <G-4 /> <G-4 /> <G-4 /> - <truck> <hard /> - <tree> <M-16 /> </tree> </truck> <G-4 /> <G-4 /> <G-4 /> <G-4 /> - <truck> <hard /> - <tree> <M-16 /> </tree> </truck> <G-4 /> <G-4 /> <G-4 /> <G-4 /> - <truck> <hard /> - <tree> <M-16 /> </tree> </truck> <G-4 /> <G-4 /> <G-4 /> <G-4 /> </Trucks>
<?xml version="1.0" encoding="utf-8"?> <Trucks id="" Port="" ip=""> <truck> <hard /> <tree> <M-16> <G-4 /> <G-4 /> <G-4 /> <G-4 /> </M-16> </tree> </truck> <truck> <hard /> <tree> <M-16> <G-4 /> <G-4 /> <G-4 /> <G-4 /> </M-16> </tree> </truck> <truck> <hard /> <tree> <M-16> <G-4 /> <G-4 /> <G-4 /> <G-4 /> </M-16> </tree> </truck> <truck> <hard /> <tree> <M-16> <G-4 /> <G-4 /> <G-4 /> <G-4 /> </M-16> </tree> </truck> </Trucks>
Решение задачи: «Формирование XML»
textual
Листинг программы
XElement xmlDoc = new XElement("Trucks", new XAttribute("id", ""), new XAttribute("Port", ""), new XAttribute("ip", "")); for (int v = 0; v < 4; v++) { XElement m16 = new XElement("M-16"); for (int i = 0; i < 4; i++) { m16.Add(new XElement("G-4")); } xmlDoc.Add(new XElement("truck", new XElement("hard"), new XElement("tree", m16))); }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д