本文整理汇总了C#中XElement.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.ToString方法的具体用法?C# XElement.ToString怎么用?C# XElement.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XElement
的用法示例。
在下文中一共展示了XElement.ToString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var headerNames = new [] { "", "X", "Y", "Z" };
var headerColumns = headerNames.Select(name =>
new XElement
(
"th",
name,
new XAttribute("text-align", "center")
)
);
var rows = Enumerable.Range(0, 4)
.Select
(
rowIndex =>
new XElement
(
"tr",
new XElement("td", rowIndex),
Enumerable.Range(0, 4)
.Select
(
colIndex =>
new XElement
(
"td",
colIndex,
new XAttribute("text-align", "center")
)
)
)
);
var xml = new XElement
(
"table",
new XElement
(
"thead",
new XElement("tr", headerColumns),
new XElement("tbody", rows)
)
);
Console.WriteLine(xml.ToString());
}
示例2: LoadParameterToSav
protected static void LoadParameterToSav(PawnParameter parameter, XElement xElement)
{
try
{
xElement.GetValueAttribute().Value = (parameter.Value.ToInt64()).ToString();
}
catch (Exception ex)
{
throw new XmlException(string.Format(
"Error exporting parameter to .sav file element: {0}.",
xElement.ToString()),
ex);
}
}
示例3: SaveTransactions
private void SaveTransactions(List<Transaction> transactions)
{
Uri accountUri = new Uri("/Accounts/Transactions/Transactions.xml", UriKind.Relative);
using (Package package = ZipPackage.Open(this.FilePath, System.IO.FileMode.OpenOrCreate)) {
// Either get the existing PackagePart or create a new one
PackagePart accountPart = null;
if (package.PartExists(accountUri)) {
accountPart = package.GetPart(accountUri);
} else {
accountPart = package.CreatePart(accountUri, "text/xml");
}
XElement resultingXElement = new XElement("Transactions");
TransactionXElementAdapter adapter = new TransactionXElementAdapter();
foreach (Transaction transaction in transactions) {
resultingXElement.Add(adapter.ToXElement(transaction));
}
using (StreamWriter sw = new StreamWriter(accountPart.GetStream())) {
sw.Write(resultingXElement.ToString());
}
}
}