本文整理汇总了C#中System.Xml.XmlWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# XmlWriter.Write方法的具体用法?C# XmlWriter.Write怎么用?C# XmlWriter.Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlWriter
的用法示例。
在下文中一共展示了XmlWriter.Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteProductToXml
/// <summary>
/// Writes a single product
/// </summary>
/// <param name="writer">The XML writer</param>
/// <param name="product">The product</param>
/// <param name="context">Context objects</param>
public virtual void WriteProductToXml(XmlWriter writer, Product product, XmlExportContext context)
{
var culture = CultureInfo.InvariantCulture;
var productTemplate = context.ProductTemplates.FirstOrDefault(x => x.Id == product.ProductTemplateId);
writer.Write("Id", product.Id.ToString());
writer.Write("Name", product.Name);
writer.Write("SeName", product.GetSeName(0, true, false));
writer.Write("ShortDescription", product.ShortDescription, null, true);
writer.Write("FullDescription", product.FullDescription, null, true);
writer.Write("AdminComment", product.AdminComment);
writer.Write("ProductTemplateId", product.ProductTemplateId.ToString());
writer.Write("ProductTemplateViewPath", productTemplate == null ? "" : productTemplate.ViewPath);
writer.Write("ShowOnHomePage", product.ShowOnHomePage.ToString());
writer.Write("HomePageDisplayOrder", product.HomePageDisplayOrder.ToString());
writer.Write("MetaKeywords", product.MetaKeywords);
writer.Write("MetaDescription", product.MetaDescription);
writer.Write("MetaTitle", product.MetaTitle);
writer.Write("AllowCustomerReviews", product.AllowCustomerReviews.ToString());
writer.Write("ApprovedRatingSum", product.ApprovedRatingSum.ToString());
writer.Write("NotApprovedRatingSum", product.NotApprovedRatingSum.ToString());
writer.Write("ApprovedTotalReviews", product.ApprovedTotalReviews.ToString());
writer.Write("NotApprovedTotalReviews", product.NotApprovedTotalReviews.ToString());
writer.Write("Published", product.Published.ToString());
writer.Write("CreatedOnUtc", product.CreatedOnUtc.ToString(culture));
writer.Write("UpdatedOnUtc", product.UpdatedOnUtc.ToString(culture));
writer.Write("SubjectToAcl", product.SubjectToAcl.ToString());
writer.Write("LimitedToStores", product.LimitedToStores.ToString());
writer.Write("ProductTypeId", product.ProductTypeId.ToString());
writer.Write("ParentGroupedProductId", product.ParentGroupedProductId.ToString());
writer.Write("Sku", product.Sku);
writer.Write("ManufacturerPartNumber", product.ManufacturerPartNumber);
writer.Write("Gtin", product.Gtin);
writer.Write("IsGiftCard", product.IsGiftCard.ToString());
writer.Write("GiftCardTypeId", product.GiftCardTypeId.ToString());
writer.Write("RequireOtherProducts", product.RequireOtherProducts.ToString());
writer.Write("RequiredProductIds", product.RequiredProductIds);
writer.Write("AutomaticallyAddRequiredProducts", product.AutomaticallyAddRequiredProducts.ToString());
writer.Write("IsDownload", product.IsDownload.ToString());
writer.Write("DownloadId", product.DownloadId.ToString());
writer.Write("UnlimitedDownloads", product.UnlimitedDownloads.ToString());
writer.Write("MaxNumberOfDownloads", product.MaxNumberOfDownloads.ToString());
writer.Write("DownloadExpirationDays", product.DownloadExpirationDays.HasValue ? product.DownloadExpirationDays.ToString() : "");
writer.Write("DownloadActivationType", product.DownloadActivationType.ToString());
writer.Write("HasSampleDownload", product.HasSampleDownload.ToString());
writer.Write("SampleDownloadId", product.SampleDownloadId.ToString());
writer.Write("HasUserAgreement", product.HasUserAgreement.ToString());
writer.Write("UserAgreementText", product.UserAgreementText);
writer.Write("IsRecurring", product.IsRecurring.ToString());
writer.Write("RecurringCycleLength", product.RecurringCycleLength.ToString());
writer.Write("RecurringCyclePeriodId", product.RecurringCyclePeriodId.ToString());
writer.Write("RecurringTotalCycles", product.RecurringTotalCycles.ToString());
writer.Write("IsShipEnabled", product.IsShipEnabled.ToString());
writer.Write("IsFreeShipping", product.IsFreeShipping.ToString());
writer.Write("AdditionalShippingCharge", product.AdditionalShippingCharge.ToString(culture));
writer.Write("IsTaxExempt", product.IsTaxExempt.ToString());
writer.Write("TaxCategoryId", product.TaxCategoryId.ToString());
writer.Write("ManageInventoryMethodId", product.ManageInventoryMethodId.ToString());
writer.Write("StockQuantity", product.StockQuantity.ToString());
writer.Write("DisplayStockAvailability", product.DisplayStockAvailability.ToString());
writer.Write("DisplayStockQuantity", product.DisplayStockQuantity.ToString());
writer.Write("MinStockQuantity", product.MinStockQuantity.ToString());
writer.Write("LowStockActivityId", product.LowStockActivityId.ToString());
writer.Write("NotifyAdminForQuantityBelow", product.NotifyAdminForQuantityBelow.ToString());
writer.Write("BackorderModeId", product.BackorderModeId.ToString());
writer.Write("AllowBackInStockSubscriptions", product.AllowBackInStockSubscriptions.ToString());
writer.Write("OrderMinimumQuantity", product.OrderMinimumQuantity.ToString());
writer.Write("OrderMaximumQuantity", product.OrderMaximumQuantity.ToString());
writer.Write("AllowedQuantities", product.AllowedQuantities);
writer.Write("DisableBuyButton", product.DisableBuyButton.ToString());
writer.Write("DisableWishlistButton", product.DisableWishlistButton.ToString());
writer.Write("AvailableForPreOrder", product.AvailableForPreOrder.ToString());
writer.Write("CallForPrice", product.CallForPrice.ToString());
writer.Write("Price", product.Price.ToString(culture));
writer.Write("OldPrice", product.OldPrice.ToString(culture));
writer.Write("ProductCost", product.ProductCost.ToString(culture));
writer.Write("SpecialPrice", product.SpecialPrice.HasValue ? product.SpecialPrice.Value.ToString(culture) : "");
writer.Write("SpecialPriceStartDateTimeUtc", product.SpecialPriceStartDateTimeUtc.HasValue ? product.SpecialPriceStartDateTimeUtc.Value.ToString(culture) : "");
writer.Write("SpecialPriceEndDateTimeUtc", product.SpecialPriceEndDateTimeUtc.HasValue ? product.SpecialPriceEndDateTimeUtc.Value.ToString(culture) : "");
writer.Write("CustomerEntersPrice", product.CustomerEntersPrice.ToString());
writer.Write("MinimumCustomerEnteredPrice", product.MinimumCustomerEnteredPrice.ToString(culture));
writer.Write("MaximumCustomerEnteredPrice", product.MaximumCustomerEnteredPrice.ToString(culture));
writer.Write("HasTierPrices", product.HasTierPrices.ToString());
writer.Write("HasDiscountsApplied", product.HasDiscountsApplied.ToString());
writer.Write("Weight", product.Weight.ToString(culture));
writer.Write("Length", product.Length.ToString(culture));
writer.Write("Width", product.Width.ToString(culture));
writer.Write("Height", product.Height.ToString(culture));
writer.Write("AvailableStartDateTimeUtc", product.AvailableStartDateTimeUtc.HasValue ? product.AvailableStartDateTimeUtc.Value.ToString(culture) : "");
writer.Write("AvailableEndDateTimeUtc", product.AvailableEndDateTimeUtc.HasValue ? product.AvailableEndDateTimeUtc.Value.ToString(culture) : "");
writer.Write("BasePriceEnabled", product.BasePriceEnabled.ToString());
writer.Write("BasePriceMeasureUnit", product.BasePriceMeasureUnit);
//.........这里部分代码省略.........
示例2: WriteQuantityUnit
protected virtual void WriteQuantityUnit(XmlWriter writer, XmlExportContext context, QuantityUnit quantityUnit)
{
if (quantityUnit != null)
{
writer.WriteStartElement("QuantityUnit");
writer.Write("Id", quantityUnit.Id.ToString());
writer.Write("Name", quantityUnit.Name);
writer.Write("Description", quantityUnit.Description);
writer.Write("DisplayLocale", quantityUnit.DisplayLocale);
writer.Write("DisplayOrder", quantityUnit.DisplayOrder.ToString());
writer.Write("IsDefault", quantityUnit.IsDefault.ToString());
WriteLocalized(writer, context, lang =>
{
writer.Write("Name", quantityUnit.GetLocalized(x => x.Name, lang.Id, false, false), lang);
writer.Write("Description", quantityUnit.GetLocalized(x => x.Description, lang.Id, false, false), lang);
});
writer.WriteEndElement();
}
}
示例3: WriteCategories
protected virtual void WriteCategories(XmlWriter writer, int parentCategoryId)
{
var categories = _categoryService.GetAllCategoriesByParentCategoryId(parentCategoryId, true);
if (categories != null && categories.Count > 0)
{
foreach (var category in categories)
{
writer.WriteStartElement("Category");
writer.Write("Id", category.Id.ToString());
writer.Write("Name", category.Name);
writer.Write("FullName", category.FullName);
writer.Write("Description", category.Description);
writer.Write("BottomDescription", category.BottomDescription);
writer.Write("CategoryTemplateId", category.CategoryTemplateId.ToString());
writer.Write("MetaKeywords", category.MetaKeywords);
writer.Write("MetaDescription", category.MetaDescription);
writer.Write("MetaTitle", category.MetaTitle);
writer.Write("SeName", category.GetSeName(0, true, false));
writer.Write("ParentCategoryId", category.ParentCategoryId.ToString());
writer.Write("PageSize", category.PageSize.ToString());
writer.Write("AllowCustomersToSelectPageSize", category.AllowCustomersToSelectPageSize.ToString());
writer.Write("PageSizeOptions", category.PageSizeOptions);
writer.Write("PriceRanges", category.PriceRanges);
writer.Write("ShowOnHomePage", category.ShowOnHomePage.ToString());
writer.Write("HasDiscountsApplied", category.HasDiscountsApplied.ToString());
writer.Write("Published", category.Published.ToString());
writer.Write("Deleted", category.Deleted.ToString());
writer.Write("DisplayOrder", category.DisplayOrder.ToString());
writer.Write("CreatedOnUtc", category.CreatedOnUtc.ToString());
writer.Write("UpdatedOnUtc", category.UpdatedOnUtc.ToString());
writer.Write("SubjectToAcl", category.SubjectToAcl.ToString());
writer.Write("LimitedToStores", category.LimitedToStores.ToString());
writer.Write("Alias", category.Alias);
writer.Write("DefaultViewMode", category.DefaultViewMode);
writer.WriteStartElement("Products");
var productCategories = _categoryService.GetProductCategoriesByCategoryId(category.Id, 0, int.MaxValue, true);
foreach (var productCategory in productCategories)
{
var product = productCategory.Product;
if (product != null && !product.Deleted)
{
writer.WriteStartElement("ProductCategory");
writer.Write("ProductCategoryId", productCategory.Id.ToString());
writer.Write("ProductId", productCategory.ProductId.ToString());
writer.Write("IsFeaturedProduct", productCategory.IsFeaturedProduct.ToString());
writer.Write("DisplayOrder", productCategory.DisplayOrder.ToString());
writer.WriteEndElement();
}
}
writer.WriteEndElement();
writer.WriteStartElement("SubCategories");
WriteCategories(writer, category.Id);
writer.WriteEndElement();
writer.WriteEndElement();
}
}
}
示例4: WritePicture
protected virtual void WritePicture(XmlWriter writer, XmlExportContext context, Picture picture, int thumbSize, int defaultSize)
{
if (picture != null)
{
writer.WriteStartElement("Picture");
writer.Write("Id", picture.Id.ToString());
writer.Write("SeoFileName", picture.SeoFilename);
writer.Write("MimeType", picture.MimeType);
writer.Write("ThumbImageUrl", _pictureService.GetPictureUrl(picture, thumbSize, false, context.Store.Url));
writer.Write("ImageUrl", _pictureService.GetPictureUrl(picture, defaultSize, false, context.Store.Url));
writer.Write("FullSizeImageUrl", _pictureService.GetPictureUrl(picture, 0, false, context.Store.Url));
writer.WriteEndElement();
}
}
示例5: Serialize
/// <summary>
///
/// </summary>
/// <param name="instance"></param>
/// <returns></returns>
public string Serialize(object instance)
{
if (instance == null)
throw new ArgumentNullException("instance");
var writer = new XmlWriter { Owner = this };
var type = instance.GetType();
var doc = new XDocument();
XElement root = null;
if (Types.ByteArray == type)
root = writer.WriteByteArray(instance as byte[]);
else if (type.IsCollectionTypeExcludeStringAndDictionaryType())
root = writer.WriteList(instance as IEnumerable);
else //TODO:字典,泛型对象需要检查
{
var name = type.Name;
root = new XElement(name.AsNamespaced(Namespace));
writer.Write(root, instance);
}
if (RootElement.HasValue())
doc.Add(new XElement(RootElement.AsNamespaced(Namespace), root));
else
doc.Add(root);
return doc.ToString();
}