Csharp/C Sharp/XML LINQ/XDeclaration — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:33, 26 мая 2010
Creating a Declaration
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass {
public static void Main() {
XDocument xDocument = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
new XElement("BookParticipant"));
Console.WriteLine(xDocument);
}
}
Creating a Declaration and Setting the Document"s Declaration Property to It
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass {
public static void Main() {
XDocument xDocument = new XDocument(new XElement("BookParticipant"));
XDeclaration xDeclaration = new XDeclaration("1.0", "UTF-8", "yes"); xDocument.Declaration = xDeclaration;
Console.WriteLine(xDocument);
}
}
Use XDeclaration,XElement, XAttribute to create an XDocument
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq;
using System.Reflection;
using System.Xml.Linq;
class Program {
static void Main(string[] args) {
XDocument xml = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
new XElement("people",
new XElement("idperson",
new XAttribute("id", 1),
new XAttribute("year", 2004),
new XAttribute("salary", "100"))));
System.IO.StringWriter sw = new System.IO.StringWriter();
xml.Save(sw);
Console.WriteLine(sw);
}
}