Ayrıca string türünden bir xml eklemek için aşağıdaki bir örnek vardır.
string xmlFromFile = System.IO.File.ReadAllText("kod.txt"); XNamespace sh = "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"; XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance"; XNamespace ef = "http://www.efatura.gov.tr/package-namespace"; XElement root = new XElement(sh + "StandardBusinessDocument", new XAttribute(xsi + "schemaLocation", "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader PackageProxy_1_2.xsd"), new XAttribute(XNamespace.Xmlns + "sh", "http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"), new XAttribute(XNamespace.Xmlns + "ef", "http://www.efatura.gov.tr/package-namespace"), new XAttribute(XNamespace.Xmlns + "xsi", "http://www.w3.org/2001/XMLSchema-instance"), new XElement(sh + "StandardBusinessDocumentHeader", new XElement(sh + "HeaderVersion", "1"), new XElement(sh + "Sender", new XElement(sh + "Identifier", "XXX"), new XElement(sh + "ContactInformation", new XElement(sh + "Contact", "XXX"), new XElement(sh + "ContactTypeIdentifier", "XXX") ),//ContactInformation new XElement(sh + "ContactInformation", new XElement(sh + "Contact", "XXX"), new XElement(sh + "ContactTypeIdentifier", "XXX") ) ),//Sender new XElement(sh + "Receiver", new XElement(sh + "Identifier", "XXX"), new XElement(sh + "ContactInformation", new XElement(sh + "Contact", "XXX"), new XElement(sh + "ContactTypeIdentifier", "XXX") ),//ContactInformation new XElement(sh + "ContactInformation", new XElement(sh + "Contact", "XXX"), new XElement(sh + "ContactTypeIdentifier", "XXX") ) ),//Receiver new XElement(sh + "DocumentIdentification", new XElement(sh+ "Standard", "XXX"), new XElement(sh+ "TypeVersion", "XXX"), new XElement(sh+ "InstanceIdentifier", "XXX"), new XElement(sh+ "Type", "XXX"), new XElement(sh+ "CreationDateAndTime", DateTime.Now.ToString("s")) ),//DocumentIdentification new XElement(sh + "Manifest", new XElement(sh+ "NumberOfItems", "XXX"), new XElement(sh+ "ManifestItem", new XElement(sh+"MimeTypeQualifierCode", "XXX"), new XElement(sh+ "UniformResourceIdentifier"), new XElement(sh + "Description"), new XElement(sh+ "LanguageCode", "XXX") )//ManifestItem )//Manifest ),//StandardBusinessDocumentHeader new XElement(ef+ "Package", new XElement("Elements", new XElement("ElementType", "XXX"), new XElement("ElementCount", "XXX"), //Düz xml metnini xml içerisine eklemek için aşağıdaki satırı kullanıyoruz. XElement.Parse(xmlFromFile) ) )//Package );