本文整理汇总了C#中System.Xml.Linq.XDocument.Save方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.Save方法的具体用法?C# XDocument.Save怎么用?C# XDocument.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDefinitions
public void CreateDefinitions(WizardConfiguration wizardConfiguration)
{
var projectCollection = new XElement(Ns + "ProjectCollection");
var doc = new XDocument(
new XElement(Ns + "VSTemplate",
new XAttribute("Version", "3.0.0"),
new XAttribute("Type", "ProjectGroup"),
new XElement(Ns + "TemplateData",
new XElement(Ns + "Name", wizardConfiguration.Name),
new XElement(Ns + "Description", wizardConfiguration.Description),
new XElement(Ns + "ProjectType", wizardConfiguration.ProjectType),
new XElement(Ns + "DefaultName", wizardConfiguration.DefaultName),
new XElement(Ns + "SortOrder", wizardConfiguration.SortOrder),
new XElement(Ns + "Icon", wizardConfiguration.IconName)),
new XElement(Ns + "TemplateContent", projectCollection),
MakeWizardExtension(
"LogoFX.Tools.Templates.Wizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
$"LogoFX.Tools.Templates.Wizard.SolutionWizard")
));
XmlWriterSettings settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = true
};
var definitionFile = GetDefinitionFileName();
using (XmlWriter xw = XmlWriter.Create(definitionFile, settings))
{
doc.Save(xw);
}
}
示例2: btnSave_Click
protected void btnSave_Click(object sender, EventArgs e)
{
doc = XDocument.Load(Server.MapPath("~/App_Data/Images.xml"));
if (this.drpLetters.SelectedIndex > 0) // Edit mode
{
IEnumerable<XElement> elements = doc.Element("Images").Elements("Image").Where(an => an.Attribute("id").Value == this.drpLetters.SelectedValue);
foreach (XElement item in elements)
{
item.Attribute("isActive").Value = this.chkIsActive.Checked.ToString();
item.Element("Title").Value = this.txtTitle.Text;
}
doc.Save(Server.MapPath("~/App_Data/Images.xml"));
if (this.fluLetter.HasFile)
{
if (this.fluLetter.PostedFile.ContentType.Equals("image/pjpeg") || this.fluLetter.PostedFile.ContentType.Equals("image/x-png"))
{
string file = string.Format("{0}/{1}.jpg", Server.MapPath("~/LettImg"), this.drpLetters.SelectedValue);
System.IO.File.Delete(file);
this.fluLetter.PostedFile.SaveAs(file);
}
else
{
this.lblMessage.Text = "فرمت عکس jpg نمیباشد";
}
}
this.lblMessage.Text = Public.EDITMESSAGE;
}
else // Add mode
{
if (this.fluLetter.HasFile)
{
if (this.fluLetter.PostedFile.ContentType.Equals("image/pjpeg") || this.fluLetter.PostedFile.ContentType.Equals("image/x-png"))
{
string maxId = doc.Element("Images").Elements("Image").Max(tst => tst.Attribute("id").Value);
string nextId = maxId == null ? "1" : (byte.Parse(maxId) + 1).ToString();
doc.Element("Images").Add(new XElement("Image", new XAttribute("id", nextId),
new XAttribute("isActive", this.chkIsActive.Checked.ToString()),
new XElement("Title", this.txtTitle.Text.Trim())));
doc.Save(Server.MapPath("~/App_Data/Images.xml"));
this.fluLetter.PostedFile.SaveAs(string.Format("{0}/{1}.jpg", Server.MapPath("~/LettImg"), nextId));
this.lblMessage.Text = Public.SAVEMESSAGE;
}
else
{
this.lblMessage.Text = "فرمت عکس jpg نمیباشد";
}
}
}
this.drpLetters.DataSource = doc.Element("Images").Elements("Image").Select(an => new { Id = an.Attribute("id").Value, Title = an.Element("Title").Value });
this.drpLetters.DataBind();
this.drpLetters.Items.Insert(0, "- جدید -");
this.drpLetters.SelectedIndex = 0;
this.chkIsActive.Checked = false;
this.txtTitle.Text = null;
this.imgLetter.ImageUrl = null;
}
示例3: Main
private static void Main()
{
helper.ConsoleMio.Setup();
helper.ConsoleMio.PrintHeading("Filter Albums using XDocument");
string selctedFile = helper.SelectFileToOpen("catalogue.xml|catalogue.xml");
var originalDoc = XDocument.Load(selctedFile);
XNamespace ns = originalDoc.Root.GetDefaultNamespace();
var albums = new XDocument(new XElement("albums",
from album in originalDoc.Descendants(ns + "album")
select new XElement(
"album"
, album.Element(ns + "name")
, album.Element(ns + "artist")
)
));
string saveLocation = helper.SelectSaveLocation("XML document|*.xml");
albums.Save(saveLocation);
helper.ConsoleMio.PrintColorText("Completed\n ", ConsoleColor.Green);
helper.ConsoleMio.Restart(Main);
}
示例4: OnSubmitButton
protected void OnSubmitButton(Object s, EventArgs e)
{
// Create the XML document
XDocument xml = new XDocument(
new XElement("order",
new XElement("reference_number", order.GetReferenceNumber().ToString()),
new XElement("pizzas",
order.pizzas.Select(pizza => new XElement("pizza",
new XElement("name", pizza.name),
new XElement("base_toppings", pizza.base_toppings),
pizza.toppings.Select(topping =>
new XElement("extra_topping", topping.name)),
new XElement("cost", pizza.Cost().ToString("c"))))),
new XElement("total_price", order.Cost().ToString("c")),
new XElement("order_time", DateTime.Now.ToString())));
// Write the XML to file
// TODO(topher): where should this file be saved?
string output_filename = @"C:\Users\topher\Documents\order_" +
order.GetReferenceNumber() + ".xml";
using (System.IO.FileStream fs =
System.IO.File.Create(output_filename))
{
xml.Save(fs);
}
Response.Redirect("OrderComplete.aspx");
}
示例5: ExportEventLogButton_Click
private async void ExportEventLogButton_Click(object sender, RoutedEventArgs e)
{
XDocument doc = new XDocument(
new XDeclaration("1.0", "UTF-8", "true"),
new XElement("LogEntries",
from entry in (this.DataContext as MainViewModel).LogEntries
select new XElement("LogEntry",
new XElement("Date", entry.EventDateTimeUTC),
new XElement("Type", entry.Level),
new XElement("DeploymentId", entry.DeploymentId),
new XElement("Role", entry.Role),
new XElement("Instance", entry.RoleInstance),
new XElement("Message", entry.Message)
)
)
);
// Configure save file dialog box
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "Export.xml";
// Show save file dialog box
if (dlg.ShowDialog() == true)
{
doc.Save(dlg.FileName);
}
}
示例6: XmlLoggerBasicTest
public void XmlLoggerBasicTest()
{
var path = @"x:\deployments\1234\log.xml";
var fileSystem = new Mock<IFileSystem>();
var file = new Mock<FileBase>();
var id = Guid.NewGuid().ToString();
var message = Guid.NewGuid().ToString();
var doc = new XDocument(new XElement("entries",
new XElement("entry",
new XAttribute("time", "2013-12-08T01:58:24.0247841Z"),
new XAttribute("id", id),
new XAttribute("type", "0"),
new XElement("message", message)
)
));
var mem = new MemoryStream();
doc.Save(mem);
// Setup
fileSystem.SetupGet(f => f.File)
.Returns(file.Object);
file.Setup(f => f.Exists(path))
.Returns(true);
file.Setup(f => f.OpenRead(path))
.Returns(() => { mem.Position = 0; return mem; });
// Test
var logger = new XmlLogger(fileSystem.Object, path, Mock.Of<IAnalytics>());
var entries = logger.GetLogEntries();
// Assert
Assert.Equal(1, entries.Count());
Assert.Equal(id, entries.First().Id);
Assert.Equal(message, entries.First().Message);
}
示例7: Index
public ActionResult Index()
{
var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));
var indexElement = new XElement(SitemapXmlNamespace + "sitemapindex");
foreach (var sitemapData in _sitemapRepository.GetAllSitemapData())
{
var sitemapElement = new XElement(
SitemapXmlNamespace + "sitemap",
new XElement(SitemapXmlNamespace + "loc", _sitemapRepository.GetSitemapUrl(sitemapData))
);
indexElement.Add(sitemapElement);
}
doc.Add(indexElement);
Response.Filter = new GZipStream(Response.Filter, CompressionMode.Compress);
Response.AppendHeader("Content-Encoding", "gzip");
byte[] sitemapIndexData;
using (var ms = new MemoryStream())
{
var xtw = new XmlTextWriter(ms, Encoding.UTF8);
doc.Save(xtw);
xtw.Flush();
sitemapIndexData = ms.ToArray();
}
return new FileContentResult(sitemapIndexData, "text/xml");
}
示例8: ExportGrammarSketch
/// <summary>
/// Exports data for the grammar sketch.
/// </summary>
/// <param name="outputPath">The output path.</param>
/// <param name="languageProject">The language project.</param>
public static void ExportGrammarSketch(string outputPath, ILangProject languageProject)
{
if (string.IsNullOrEmpty(outputPath)) throw new ArgumentNullException("outputPath");
if (languageProject == null) throw new ArgumentNullException("languageProject");
var servLoc = languageProject.Cache.ServiceLocator;
const Icu.UNormalizationMode mode = Icu.UNormalizationMode.UNORM_NFC;
var morphologicalData = languageProject.MorphologicalDataOA;
var doc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("M3Dump",
ExportLanguageProject(languageProject, mode),
ExportPartsOfSpeech(languageProject, mode),
ExportPhonologicalData(languageProject.PhonologicalDataOA, mode),
new XElement("MoMorphData",
ExportCompoundRules(servLoc.GetInstance<IMoEndoCompoundRepository>(),
servLoc.GetInstance<IMoExoCompoundRepository>(), mode),
ExportAdhocCoProhibitions(morphologicalData, mode),
ExportProdRestrict(morphologicalData, mode)),
ExportMorphTypes(servLoc.GetInstance<IMoMorphTypeRepository>(), mode),
ExportLexEntryInflTypes(servLoc.GetInstance<ILexEntryInflTypeRepository>(), mode),
ExportLexiconFull(servLoc, mode),
ExportFeatureSystem(languageProject.MsFeatureSystemOA, "FeatureSystem", mode),
ExportFeatureSystem(languageProject.PhFeatureSystemOA, "PhFeatureSystem", mode)
)
);
doc.Save(outputPath);
}
示例9: Save
internal static void Save(QuoteList inQuoteList)
{
XDocument document = new XDocument();
document.Add(XElement.Parse(@"<QuoteList xmlns='http://kiander.com'></QuoteList>"));
document.Root.Add(new XAttribute("QuoteListId", inQuoteList.Id));
foreach (IQuote quote in inQuoteList.Quotes)
{
XElement quoteRecord = new XElement("QuoteRecord");
quoteRecord.Add(new XElement("QuoteID", quote.Id));
quoteRecord.Add(new XElement("Quote", quote.Text));
quoteRecord.Add(new XElement("Author", quote.Author));
XElement categories = new XElement("Categories");
if (quote.Categories != null)
{
foreach (string category in quote.Categories)
{
categories.Add(new XElement("Category", category));
}
}
if (quote.Categories == null || quote.Categories.Count < 1)
{
categories.Add(new XElement("Category", string.Empty));
}
quoteRecord.Add(categories);
document.Root.Add(quoteRecord);
}
if (File.Exists(DataFileHelper.FullPath(inQuoteList.Id)))
File.Delete(DataFileHelper.FullPath(inQuoteList.Id));
document.Save(DataFileHelper.FullPath(inQuoteList.Id));
}
示例10: login
/// <summary>
/// Đăng nhập vào hệ thống
/// </summary>
/// <param name="tenDangNhap"></param>
/// <param name="matKhau"></param>
/// <returns></returns>
public static async Task<bool> login(string tenDangNhap, string matKhau, bool isRemember)
{
try
{
matKhau = Utilities.EncryptMD5(matKhau);
var result = await SystemInfo.DatabaseModel.login(tenDangNhap, matKhau);
if (!result)
{
SystemInfo.IsDangNhap = false;
SystemInfo.MaNguoiDung = -1;
SystemInfo.TenDangNhap = null;
SystemInfo.MatKhauDangNhap = null;
}
else
{
SystemInfo.IsDangNhap = true;
NguoiDung nguoiDung = await SystemInfo.DatabaseModel.getNguoiDungTenDangNhap(tenDangNhap);
SystemInfo.MaNguoiDung = nguoiDung.MaNguoiDung;
SystemInfo.TenDangNhap = tenDangNhap;
SystemInfo.MatKhauDangNhap = matKhau;
if (!(await SystemInfo.DatabaseModel.insertNguoiDungLocal(nguoiDung.MaNguoiDung, nguoiDung.HoTen, nguoiDung.NgaySinh,
nguoiDung.Email, nguoiDung.SoDienThoai)))
{
await SystemInfo.DatabaseModel.updateNguoiDung(nguoiDung.MaNguoiDung, nguoiDung.HoTen, nguoiDung.NgaySinh,
nguoiDung.SoDienThoai);
}
if (isRemember)
{
StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("AppConfig.qltcconfig");
using (IRandomAccessStream writeStream = await file.OpenAsync(FileAccessMode.ReadWrite))
{
System.IO.Stream s = writeStream.AsStreamForWrite();
System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
settings.Async = true;
settings.Indent = true;
settings.CheckCharacters = false;
using (System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(s, settings))
{
XDocument xdoc = new XDocument();
XElement element = new XElement("ThongTinDangNhap");
element.Add(new XElement("MaNguoiDung", nguoiDung.MaNguoiDung + ""));
element.Add(new XElement("TenDangNhap", tenDangNhap));
xdoc.Add(element);
writer.Flush();
xdoc.Save(writer);
}
}
}
}
return result;
}
catch (Exception ex)
{
throw ex;
}
}
示例11: CreateXml
public static void CreateXml(IEnumerable<Pilot> pilots, string path)
{
var xmlDoc = new XDocument();
var xmlRoot = new XElement("pilots");
xmlDoc.Add(xmlRoot);
foreach (var pilot in pilots)
{
var pilotEntry = new XElement("pilot");
xmlRoot.Add(pilotEntry);
var pilotName = new XElement("name", pilot.Name);
pilotEntry.Add(pilotName);
var pilotPosition = new XElement("position", pilot.Position);
pilotEntry.Add(pilotPosition);
if (pilot.SupervisorId != null)
{
var pilotSupervisorId = new XElement("supervisorId", pilot.SupervisorId);
pilotEntry.Add(pilotSupervisorId);
}
}
xmlDoc.Save(path);
}
示例12: Write
public static void Write(IEnumerable<LocalSong> songs, IEnumerable<PlaylistInfo> playlists, Stream targetStream)
{
var document = new XDocument(
new XElement("Root",
new XElement("Version", "1.0.0"),
new XElement("Songs", songs.Select(song =>
new XElement("Song",
new XAttribute("Album", song.Album),
new XAttribute("Artist", song.Artist),
new XAttribute("AudioType", song.AudioType),
new XAttribute("Duration", song.Duration.Ticks),
new XAttribute("Genre", song.Genre),
new XAttribute("Path", song.OriginalPath),
new XAttribute("Title", song.Title),
new XAttribute("TrackNumber", song.TrackNumber)))),
new XElement("Playlists", playlists.Select(playlist =>
new XElement("Playlist",
new XAttribute("Name", playlist.Name),
new XElement("Entries", playlist.Songs.Select(song =>
new XElement("Entry",
new XAttribute("Path", song.OriginalPath),
song is YoutubeSong ? new XAttribute("Title", song.Title) : null,
new XAttribute("Type", (song is LocalSong) ? "Local" : "YouTube"),
song is YoutubeSong ? new XAttribute("Duration", song.Duration.Ticks) : null))))))));
document.Save(targetStream);
}
示例13: GetXmlContents
private Action<Stream> GetXmlContents(IEnumerable<Post> model)
{
var blank = XNamespace.Get(@"http://www.sitemaps.org/schemas/sitemap/0.9");
var xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement(blank+"urlset", new XAttribute("xmlns", blank.NamespaceName)));
foreach (Post post in model)
{
var xElement = new XElement(blank+"url",
new XElement(blank + "loc", siteUrl + post.Url),
new XElement(blank + "lastmod", post.Date.ToString("yyyy-MM-dd")),
new XElement(blank + "changefreq", "weekly"),
new XElement(blank + "priority", "1.00"));
xDocument.Root.Add(xElement);
}
return stream =>
{
using (XmlWriter writer = XmlWriter.Create(stream))
{
xDocument.Save(writer);
}
};
}
示例14: ValidateSave
public void ValidateSave()
{
WorldEntity world = createTestWorld();
XElement xElement = WorldTransformer.Instance.ToXElement(world, TransformerSettings.WorldNamespace + "World");
xElement.Save("unittestsave.xml", SaveOptions.OmitDuplicateNamespaces);
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add(null, "WorldSchema1.xsd");
XDocument xDocument = new XDocument(xElement);
xDocument.AddAnnotation(SaveOptions.OmitDuplicateNamespaces);
xDocument.Save("unittest2.xml", SaveOptions.OmitDuplicateNamespaces);
XElement x1 = new XElement(TransformerSettings.WorldNamespace + "Outer");
x1.Add(new XElement(TransformerSettings.WorldNamespace + "Inner"));
x1.Save("unittest3.xml", SaveOptions.OmitDuplicateNamespaces);
string val = "";
xDocument.Validate(schemaSet, (o, vea) => {
val += o.GetType().Name + "\n";
val += vea.Message + "\n";
}, true);
Assert.AreEqual("", val);
}
示例15: SaveImages
public override void SaveImages(Stream stream)
{
var xdocument = new XDocument();
var xelement = new XElement("images");
xdocument.Add(xelement);
xdocument.Save(stream);
}