本文整理匯總了C#中System.Xml.Linq.XElement.AddFirst方法的典型用法代碼示例。如果您正苦於以下問題:C# XElement.AddFirst方法的具體用法?C# XElement.AddFirst怎麽用?C# XElement.AddFirst使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.AddFirst方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Process
public override void Process()
{
base.Process();
var element = TextTag.TagNode;
var text = DataReader.ReadText(TextTag.Expression);
XElement parent = element.Parent;
if (parent.Name == WordMl.TableRowName)
{
parent = element.Element(WordMl.SdtContentName).Element(WordMl.TableCellName);
}
var textElement = DocxHelper.CreateTextElement(element, parent, text);
var result = this.CreateDynamicContentTags
? DocxHelper.CreateDynamicContentElement(new[] { textElement }, this.TextTag.TagNode, this.DynamicContentLockingType)
: textElement;
if (element.Parent.Name != WordMl.TableRowName)
{
element.AddBeforeSelf(result);
}
else
{
var cell = new XElement(WordMl.TableCellName, result);
cell.AddFirst(element.Descendants(WordMl.TableCellPropertiesName));
element.AddBeforeSelf(cell);
}
element.Remove();
}
示例2: CompileWithBSharp
private static XElement CompileWithBSharp(XElement result)
{
var compileroptions = new BSharpConfig
{
UseInterpolation = true,
SingleSource = true
};
var compileresult = BSharpCompiler.Compile(new[] { result }, compileroptions);
var newresult = new XElement("bsharp");
foreach (var w in compileresult.Get(BSharpContextDataType.Working))
{
var copy = new XElement(w.Compiled);
if (null != w.Error)
{
copy.AddFirst(new XElement("error", new XText(w.Error.ToString())));
}
newresult.Add(copy);
}
var e = new XElement("errors");
foreach (var er in compileresult.GetErrors())
{
e.Add(XElement.Parse(new XmlSerializer().Serialize("error", er)).Element("error"));
}
if (e.HasElements)
{
newresult.Add(e);
}
result = newresult;
return result;
}
示例3: Execute
public void Execute(JobExecutionContext context)
{
try
{
log.Info("AllListJob開始更新");
var videos = ListCache.Instance.Items[new VideoNodeKey(null, 0, null)].Ver1;
var root = new XElement("vlist");
int num = 0;
foreach (var video in videos)
{
root.Add(ResponseUtils.ResponseBack(ListCache.Instance.Dictionary[video]));
num++;
}
root.AddFirst(new XElement("count", num));
ResponseUtils.SaveXml("all.xml", root);
YesterdayListCache.Instance.Refresh(videos);
SerizlizerUtils<YesterdayVideoNode>.SerializeSplitCache(YesterdayListCache.Instance.Items, _buffername);
//SerizlizerUtils<VideoNode>.SerializeSplitCache(videos, _buffername);
}
catch (Exception ex)
{
log.Error(ex);
}
finally
{
log.Info("AllListJob結束更新");
}
}
示例4: AddContentTypeMetadata
private void AddContentTypeMetadata(XElement head)
{
var meta = new XElement("meta");
meta.SetAttributeValue("http-equiv", "content-type");
meta.SetAttributeValue("content", "text/html; charset=UTF-8");
head.AddFirst(meta);
}
示例5: CreateOrder
private static OrderInfo CreateOrder(string countryCode)
{
var order = new OrderInfo();
var xElement = new XElement(CustomerDatatypes.Customer.ToString());
xElement.AddFirst(new XElement("customerCountry", new XCData("")));
order.CustomerInfo.customerInformation = new XDocument(xElement);
order.CustomerCountry = countryCode;
return order;
}
示例6: WriteVariables
/// <summary>
/// Writes the variables as xml
/// </summary>
protected void WriteVariables(XElement varXML)
{
VariableXMLWriter varWriter = new VariableXMLWriter();
foreach(Variable v in this.Model){
varWriter.ToWrite = v;
varXML.AddFirst(varWriter.Write());
}
}
示例7: Reparent
public static void Reparent(this IEnumerable<XElement> nodes, XElement parent, bool first = false)
{
var list = nodes.ToArray();
list.Remove();
if (first)
parent.AddFirst(list);
else
parent.Add(list);
}
示例8: AddElementToXml
static void AddElementToXml(DirectoryInfo rootDir, FileInfo[] files)
{
XElement nextDir = new XElement("dir");
nextDir.Add(new XAttribute("name", rootDir.FullName));
root.AddFirst(nextDir);
foreach (FileInfo file in files)
{
XElement nextFile = new XElement("file");
nextFile.Add(new XAttribute("name", file.Name));
nextDir.AddFirst(nextFile);
}
}
示例9: CreateHelpPage
public static XDocument CreateHelpPage(Uri baseUri, IEnumerable<OperationHelpInformation> operations)
{
XDocument document = CreateBaseDocument(SR2.GetString(SR2.HelpPageOperationsAt, baseUri));
XElement table = new XElement(HtmlTableElementName,
new XElement(HtmlTrElementName,
new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageUri)),
new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageMethod)),
new XElement(HtmlThElementName, SR2.GetString(SR2.HelpPageDescription))));
string lastOperation = null;
XElement firstTr = null;
int rowspan = 0;
foreach (OperationHelpInformation operationHelpInfo in operations.OrderBy(o => FilterQueryVariables(o.UriTemplate)))
{
string operationUri = FilterQueryVariables(operationHelpInfo.UriTemplate);
string description = operationHelpInfo.Description;
if (String.IsNullOrEmpty(description))
{
description = SR2.GetString(SR2.HelpPageDefaultDescription, BuildFullUriTemplate(baseUri, operationHelpInfo.UriTemplate));
}
XElement tr = new XElement(HtmlTrElementName,
new XElement(HtmlTdElementName, new XAttribute(HtmlTitleAttributeName, BuildFullUriTemplate(baseUri, operationHelpInfo.UriTemplate)),
new XElement(HtmlAElementName,
new XAttribute(HtmlRelAttributeName, HtmlOperationClass),
new XAttribute(HtmlHrefAttributeName, String.Format(CultureInfo.InvariantCulture, HelpOperationPageUrl, operationHelpInfo.Name)), operationHelpInfo.Method)),
new XElement(HtmlTdElementName, description));
table.Add(tr);
if (operationUri != lastOperation)
{
XElement td = new XElement(HtmlTdElementName, operationUri == lastOperation ? String.Empty : operationUri);
tr.AddFirst(td);
if (firstTr != null && rowspan > 1)
{
firstTr.Descendants(HtmlTdElementName).First().Add(new XAttribute(HtmlRowspanAttributeName, rowspan));
}
firstTr = tr;
rowspan = 0;
lastOperation = operationUri;
}
++rowspan;
}
if (firstTr != null && rowspan > 1)
{
firstTr.Descendants(HtmlTdElementName).First().Add(new XAttribute(HtmlRowspanAttributeName, rowspan));
}
document.Descendants(HtmlBodyElementName).First().Add(new XElement(HtmlDivElementName, new XAttribute(HtmlIdAttributeName, HtmlContentClass),
new XElement(HtmlPElementName, new XAttribute(HtmlClassAttributeName, HtmlHeading1Class), SR2.GetString(SR2.HelpPageOperationsAt, baseUri)),
new XElement(HtmlPElementName, SR2.GetString(SR2.HelpPageStaticText)),
table));
return document;
}
示例10: NodeParent
/// <summary>
/// Tests the Parent property on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeParent")]
public void NodeParent()
{
// Only elements are returned as parents from the Parent property.
// Documents are not returned.
XDocument document = new XDocument();
XNode[] nodes = new XNode[]
{
new XComment("comment"),
new XElement("element"),
new XProcessingInstruction("target", "data"),
new XDocumentType("name", "publicid", "systemid", "internalsubset")
};
foreach (XNode node in nodes)
{
Validate.IsNull(node.Parent);
document.Add(node);
Validate.IsReferenceEqual(document, node.Document);
// Parent element is null.
Validate.IsNull(node.Parent);
document.RemoveNodes();
}
// Now test the cases where an element is the parent.
nodes = new XNode[]
{
new XComment("abcd"),
new XElement("nested"),
new XProcessingInstruction("target2", "data2"),
new XText("text")
};
XElement root = new XElement("root");
document.ReplaceNodes(root);
foreach (XNode node in nodes)
{
Validate.IsNull(node.Parent);
root.AddFirst(node);
Validate.IsReferenceEqual(node.Parent, root);
root.RemoveNodes();
Validate.IsNull(node.Parent);
}
}
示例11: Convert11To12
/// <summary>
/// Convert MyDistanceNode's inputs from A,B to Input 1, Input 2 (required after the node was put into Transforms)
/// Author: MP
/// </summary>
public static string Convert11To12(string xml)
{
XDocument document = XDocument.Parse(xml);
foreach (XElement node in document.Root.Descendants("MyDistanceNode"))
{
XElement IO = new XElement("IO");
XElement InputBranches = new XElement("InputBranches");
InputBranches.Value = "2";
IO.AddFirst(InputBranches);
node.AddFirst(IO);
}
return document.ToString();
}
示例12: AllList
public string AllList(UpdateFilter filter)
{
try
{
var videos = ListCache.Instance.Items[new VideoNodeKey(null, 0, null)].Ver1;
var xml = new XElement("vlist");
var count = videos.BackPageList(filter.c,filter.s,xml);
xml.AddFirst(new XElement("count", count),
new XElement("page_count", PageUtils.PageCount(count, filter.c))
);
return xml.ToString(SaveOptions.DisableFormatting);
}
catch (Exception ex)
{
return BoxUtils.FormatErrorMsg(ex);
}
}
示例13: TagSearchSmart
public string TagSearchSmart(TagSearchFilter filter)
{
try
{
var xml = new XElement("taglist");
var count = LuceneNetUtil.TagSearch(filter, EpgIndexNode.NameField, Searcher.SegmentKeyWord(filter.k), xml);
xml.AddFirst(new XElement("count", count), new XElement("page_count", PageUtils.PageCount(count, filter.c)));
return xml.ToString(SaveOptions.DisableFormatting);
}
catch (KeyNotFoundException)
{
return NoPlatForm();
}
catch (Exception ex)
{
return BoxUtils.FormatErrorMsg(ex);
}
}
示例14: ToXmlElement
public XElement ToXmlElement()
{
try
{
var elem = new XElement(XName.Get("pattern"));
elem.SetAttributeValue(XName.Get("name"), Name);
foreach (var patternHeader in Headers)
{
var header = new XElement(XName.Get("header"));
header.SetAttributeValue(XName.Get("name"), patternHeader.Name);
header.SetAttributeValue(XName.Get("value"), patternHeader.Value);
elem.AddFirst(header);
}
if (Contexts.Count != 0)
{
var contexts = new XElement(XName.Get("contexts"));
foreach (var celem in Contexts.Select(context => context.ToXmlElement()))
{
contexts.AddFirst(celem);
}
}
foreach (var patternText in Texts)
{
var text = new XElement(XName.Get("text"));
text.SetAttributeValue(XName.Get("type"), patternText.Encoding);
text.Value = patternText.Text;
}
return elem;
}
catch (Exception e)
{
throw new PatternXmlException("Ошибка трансформации паттерна в xml формат. Подробнее в InnerException", e);
}
}
示例15: GenerateSiteElement
public virtual XElement GenerateSiteElement(PageData pageData, string url)
{
var property = pageData.Property[PropertySEOSitemaps.PropertyName] as PropertySEOSitemaps;
var element = new XElement(
SitemapXmlNamespace + "url",
new XElement(SitemapXmlNamespace + "loc", url),
new XElement(SitemapXmlNamespace + "lastmod", pageData.Saved.ToString(DateTimeFormat)),
new XElement(SitemapXmlNamespace + "changefreq", (property != null) ? property.ChangeFreq : "weekly"),
new XElement(SitemapXmlNamespace + "priority", (property != null) ? property.Priority : GetPriority(url)));
if (IsDebugMode)
{
element.AddFirst(new XComment(
string.Format(
"page ID: '{0}', name: '{1}', language: '{2}'",
pageData.PageLink.ID, pageData.PageName, pageData.LanguageBranch)));
}
return element;
}