本文整理汇总了C#中System.Xml.XmlTextWriter.WriteAttributeString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextWriter.WriteAttributeString方法的具体用法?C# XmlTextWriter.WriteAttributeString怎么用?C# XmlTextWriter.WriteAttributeString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextWriter
的用法示例。
在下文中一共展示了XmlTextWriter.WriteAttributeString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serialize
public static string Serialize(IEnumerable<MicroDataEntry> entries)
{
StringBuilder sb = new StringBuilder(3000);
using (StringWriter sw = new StringWriter(sb))
{
using (XmlTextWriter xw = new XmlTextWriter(sw))
{
xw.WriteStartElement("microData");
foreach (MicroDataEntry microDataEntry in entries)
{
xw.WriteStartElement("entry");
if (microDataEntry.ContentType.HasValue)
{
xw.WriteAttributeString("contentType", microDataEntry.ContentType.Value.ToString());
}
xw.WriteAttributeString("entryType", microDataEntry.Type.ToString());
xw.WriteAttributeString("selector", microDataEntry.Selector);
xw.WriteAttributeString("value", microDataEntry.Value);
xw.WriteEndElement();
}
xw.WriteEndElement();
}
}
return sb.ToString();
}
示例2: button1_Click
// XmlWriterSample1/form.cs
private void button1_Click(object sender, System.EventArgs e)
{
// change to match you path structure
string fileName="booknew.xml";
//create the XmlTextWriter
XmlTextWriter tw=new XmlTextWriter(fileName,null);
//set the formatting to indented
tw.Formatting=Formatting.Indented;
tw.WriteStartDocument();
//Start creating elements and attributes
tw.WriteStartElement("book");
tw.WriteAttributeString("genre","Mystery");
tw.WriteAttributeString("publicationdate","2001");
tw.WriteAttributeString("ISBN","123456789");
tw.WriteElementString("title","Case of the Missing Cookie");
tw.WriteStartElement("author");
tw.WriteElementString("name","Cookie Monster");
tw.WriteEndElement();
tw.WriteElementString("price","9.99");
tw.WriteEndElement();
tw.WriteEndDocument();
//clean up
tw.Flush();
tw.Close();
}
示例3: SaveRegister
private bool SaveRegister(string RegisterKey)
{
try
{
Encryption enc = new Encryption();
FileStream fs = new FileStream("reqlkd.dll", FileMode.Create);
XmlTextWriter w = new XmlTextWriter(fs, Encoding.UTF8);
// Khởi động tài liệu.
w.WriteStartDocument();
w.WriteStartElement("QLCV");
// Ghi một product.
w.WriteStartElement("Register");
w.WriteAttributeString("GuiNumber", enc.EncryptData(sGuiID));
w.WriteAttributeString("Serialnumber", enc.EncryptData(sSerial));
w.WriteAttributeString("KeyRegister", enc.EncryptData(RegisterKey, sSerial + sGuiID));
w.WriteEndElement();
// Kết thúc tài liệu.
w.WriteEndElement();
w.WriteEndDocument();
w.Flush();
w.Close();
fs.Close();
return true;
}
catch (Exception ex)
{
return false;
}
}
示例4: AddKey
private void AddKey(XmlTextWriter xml, string key, string value)
{
xml.WriteStartElement("add");
xml.WriteAttributeString("key", key);
xml.WriteAttributeString("value", value);
xml.WriteEndElement(); //add
}
示例5: EncodeInvoke
/// <summary>
/// Encodes a function call to be sent to Flash.
/// </summary>
/// <param name="functionName">The name of the function to call.</param>
/// <param name="arguments">Zero or more parameters to pass in to the ActonScript function.</param>
/// <returns>The XML string representation of the function call to pass to Flash</returns>
public static string EncodeInvoke(string functionName, object[] arguments)
{
StringBuilder sb = new StringBuilder();
XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb));
// <invoke name="functionName" returntype="xml">
writer.WriteStartElement("invoke");
writer.WriteAttributeString("name", functionName);
writer.WriteAttributeString("returntype", "xml");
if (arguments != null && arguments.Length > 0)
{
// <arguments>
writer.WriteStartElement("arguments");
// individual arguments
foreach (object value in arguments)
{
WriteElement(writer, value);
}
// </arguments>
writer.WriteEndElement();
}
// </invoke>
writer.WriteEndElement();
writer.Flush();
writer.Close();
return sb.ToString();
}
示例6: createRandomXML
public void createRandomXML(XmlTextWriter writer, int NUM_SENSOR, int NUM_LINK)
{
writer.WriteStartElement(XmlTag.TAG_WSN);
writer.WriteStartElement(XmlTag.TAG_DECLARATION);
writer.WriteEndElement();
writer.WriteStartElement(XmlTag.TAG_NETWORK);
writer.WriteStartElement(XmlTag.TAG_PROCESS);
writer.WriteAttributeString(XmlTag.ATTR_NAME, "Network_1");
writer.WriteAttributeString(XmlTag.ATTR_PRO_PARAM, "");
writer.WriteAttributeString(XmlTag.ATTR_ZOOM, "1");
writer.WriteAttributeString("StateCounter", "9");
//Create sensors
writer.WriteStartElement(XmlTag.TAG_SENSORS);
randomSensors(NUM_SENSOR, writer);
writer.WriteEndElement(); //End sensors
//Create links
writer.WriteStartElement(XmlTag.TAG_CHANNELS);
randomLinks(NUM_LINK, NUM_SENSOR, writer);
writer.WriteEndElement(); //End <Links>
writer.WriteEndElement(); //End <Process>
writer.WriteEndElement(); //End <Network>
writer.WriteEndElement(); //End <WSN>
}
示例7: TraverseAndGenerateXmlUsingXmlWriter
// so not cool...
private static void TraverseAndGenerateXmlUsingXmlWriter(string targetPath, XmlTextWriter writer)
{
var files = Directory.GetFiles(targetPath);
if (files.Length > 0)
{
foreach (var f in files)
{
writer.WriteStartElement("file");
writer.WriteAttributeString("name", Path.GetFileNameWithoutExtension(f));
writer.WriteEndElement();
}
}
var directories = Directory.GetDirectories(targetPath);
if (directories.Length != 0)
{
foreach (var dir in directories)
{
writer.WriteStartElement("dir");
writer.WriteAttributeString("name", new DirectoryInfo(dir).Name);
TraverseAndGenerateXmlUsingXmlWriter(dir, writer);
writer.WriteEndElement();
}
}
}
示例8: ToKML
public override void ToKML(XmlTextWriter kml)
{
kml.WriteStartElement("Schema");
kml.WriteAttributeString("name", Name);
kml.WriteAttributeString("parent", Parent);
kml.WriteEndElement();
}
示例9: Serialize
public static string Serialize(UserProfileData profile)
{
StringWriter sw = new StringWriter();
XmlTextWriter xtw = new XmlTextWriter(sw);
xtw.Formatting = Formatting.Indented;
xtw.WriteStartDocument();
xtw.WriteStartElement("user_profile");
xtw.WriteAttributeString("major_version", MAJOR_VERSION.ToString());
xtw.WriteAttributeString("minor_version", MINOR_VERSION.ToString());
xtw.WriteElementString("name", profile.Name);
xtw.WriteElementString("id", profile.ID.ToString());
xtw.WriteElementString("about", profile.AboutText);
// Not sure if we're storing this yet, need to take a look
// xtw.WriteElementString("Url", profile.Url);
// or, indeed, interests
xtw.WriteEndElement();
xtw.Close();
sw.Close();
return sw.ToString();
}
示例10: WriteXml
/// <summary>
/// Generates Burn manifest and ParameterInfo-style markup for a component search.
/// </summary>
/// <param name="writer"></param>
public override void WriteXml(XmlTextWriter writer)
{
writer.WriteStartElement("MsiComponentSearch");
this.WriteWixSearchAttributes(writer);
writer.WriteAttributeString("ComponentId", this.Guid);
if (!String.IsNullOrEmpty(this.ProductCode))
{
writer.WriteAttributeString("ProductCode", this.ProductCode);
}
if (0 != (this.Attributes & WixComponentSearchAttributes.KeyPath))
{
writer.WriteAttributeString("Type", "keyPath");
}
else if (0 != (this.Attributes & WixComponentSearchAttributes.State))
{
writer.WriteAttributeString("Type", "state");
}
else if (0 != (this.Attributes & WixComponentSearchAttributes.WantDirectory))
{
writer.WriteAttributeString("Type", "directory");
}
writer.WriteEndElement();
}
示例11: BuildEmptyLayout
protected virtual string BuildEmptyLayout([NotNull] Database database)
{
var writer = new StringWriter();
var output = new XmlTextWriter(writer)
{
Formatting = Formatting.Indented
};
output.WriteStartElement("Layout");
output.WriteAttributeString("xmlns", "http://www.sitecore.net/pathfinder/item");
var deviceItem = database.GetItem(ItemIDs.DevicesRoot);
if (deviceItem != null)
{
foreach (Item item in deviceItem.Children)
{
output.WriteStartElement("Device");
output.WriteAttributeString("Name", item.Name);
output.WriteEndElement();
}
}
output.WriteEndElement();
return writer.ToString();
}
示例12: CreateSalesReport
public static void CreateSalesReport()
{
SupermarketEntities supermarkets = new SupermarketEntities();
var queryResult =
from vendor in supermarkets.Vendors
select new
{
Vendor = vendor.VendorName,
dayToDayReprots =
from sale in supermarkets.Sales
join product in supermarkets.Products
on sale.ProductId equals product.ProductId
join report in supermarkets.Reports
on sale.ReportId equals report.ReportId
where product.VendorId == vendor.VendorId
group sale by report.ReportDate
into reportForDate
select new
{
Date = reportForDate.Key,
TotalSum = reportForDate.Sum(p => p.ProductTotalSum)
}
};
string fileName = "../../report.xml";
Encoding encoding = Encoding.GetEncoding("windows-1251");
using (XmlTextWriter writer = new XmlTextWriter(fileName, encoding))
{
writer.Formatting = Formatting.Indented;
writer.IndentChar = '\t';
writer.Indentation = 1;
writer.WriteStartDocument();
writer.WriteStartElement("sales");
foreach (var vendor in queryResult)
{
Console.WriteLine("Writing report for " + vendor.Vendor);
writer.WriteStartElement("sale");
writer.WriteAttributeString("vendor", vendor.Vendor);
foreach (var dayReport in vendor.dayToDayReprots)
{
writer.WriteStartElement("summary");
string dateString = string.Format("{0:dd-MMM-yyyy}", dayReport.Date);
writer.WriteAttributeString("date", dateString);
writer.WriteAttributeString("total-sum", dayReport.TotalSum.ToString("N2"));
writer.WriteEndElement();
}
writer.WriteEndElement();
}
writer.WriteEndDocument();
}
}
示例13: ToString
/// <summary>
///
/// </summary>
/// <returns></returns>
public override string ToString()
{
var s = new StringWriter(new StringBuilder(), CultureInfo.CurrentCulture);
var xmlWrite = new XmlTextWriter(s);
xmlWrite.WriteStartDocument();
xmlWrite.WriteStartElement("userInfo");
xmlWrite.WriteAttributeString("xmlns", "http://schemas.microsoft.com/office/Outlook/2006/OMS/serviceInfo");
xmlWrite.WriteStartElement("error");
xmlWrite.WriteAttributeString("code", this.Code.ToString());
if (this.Severity != SeverityType.Unknow)
{
xmlWrite.WriteAttributeString("severity", this.Severity.ToString());
}
xmlWrite.WriteEndElement();
if (this.Code == ErrorCode.Ok)
{
if (!string.IsNullOrEmpty(this.ReplyPhone))
{
xmlWrite.WriteElementString("replyPhone", this.ReplyPhone);
}
if (!string.IsNullOrEmpty(this.ReplyPhone))
{
xmlWrite.WriteElementString("smtpAddress", this.SmtpAddress);
}
}
xmlWrite.WriteEndElement();
xmlWrite.WriteEndDocument();
return s.GetStringBuilder().ToString();
}
示例14: AddHeaderInformation
public static void AddHeaderInformation(XmlDocument xmlDoc, QMaker qMaker)
{
StringBuilder sbH = new StringBuilder();
StringWriter tempWriterH = new StringWriter(sbH);
XmlTextWriter writerH = new XmlTextWriter(tempWriterH);
writerH.WriteStartElement("Headers");
foreach (QField gField in qMaker.Groups)
{
writerH.WriteStartElement("Header");
writerH.WriteAttributeString("Name", gField.Name);
writerH.WriteAttributeString("Description", gField.FriendlyName);
writerH.WriteEndElement();//Header
}
foreach (QField fField in qMaker.Fields)
{
writerH.WriteStartElement("Header");
writerH.WriteAttributeString("Name", fField.Name);
writerH.WriteAttributeString("Description", fField.FriendlyName);
writerH.WriteEndElement();//Header
}
writerH.WriteEndElement();//Headers
writerH.Flush();
XmlDocumentFragment xmlHeaders = xmlDoc.CreateDocumentFragment();
xmlHeaders.InnerXml = sbH.ToString();
xmlDoc.SelectSingleNode("Report").AppendChild(xmlHeaders);
}
示例15: Save_XML
public void Save_XML(string path)
{
XmlTextWriter xmlTextWriter = new XmlTextWriter(path, null);
xmlTextWriter.Formatting = Formatting.Indented;
xmlTextWriter.WriteStartDocument(false);
xmlTextWriter.WriteComment("Xml from Juan converter");
xmlTextWriter.WriteStartElement("STB");
for (int num = 0; num != this.rowcount; num++)
{
xmlTextWriter.WriteStartElement("Entry");
xmlTextWriter.WriteAttributeString("id", num.ToString());
for (int num2 = 0; num2 != this.columncount; num2++)
{
if (this.column[num2].selected)
{
xmlTextWriter.WriteStartElement("Data");
xmlTextWriter.WriteAttributeString("type", this.column[num2].columntitle);
xmlTextWriter.WriteString(this.celldata[num, num2]);
xmlTextWriter.WriteEndElement();
}
}
xmlTextWriter.WriteEndElement();
}
xmlTextWriter.WriteEndElement();
xmlTextWriter.Flush();
xmlTextWriter.Close();
xmlTextWriter.Close();
}