本文整理汇总了C#中System.Xml.Linq.XElement.AddBeforeSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.AddBeforeSelf方法的具体用法?C# XElement.AddBeforeSelf怎么用?C# XElement.AddBeforeSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.AddBeforeSelf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPropertyElement
private XElement FindPropertyElement(XElement project, string propertyName)
{
foreach (var nemerleProperty in project.Descendants(vs + propertyName))
return nemerleProperty;
// Try to add property if it's not exists
foreach (var propertyGroup in project.Elements(vs + "PropertyGroup").Where(g => !g.HasAttributes))
{
var text = propertyGroup.HasElements ? propertyGroup.FirstNode as XText : null;
var newElem = new XElement(vs + propertyName, "");
if (propertyName == "Nemerle")
propertyGroup.Add(newElem);
else
propertyGroup.AddFirst(newElem);
if (text != null)
newElem.AddBeforeSelf(text.Value);
else
newElem.AddBeforeSelf(" " + Environment.NewLine);
return newElem;
}
throw new ApplicationException("Incorrect format of project file. The project must contains '" + propertyName + "' property.");
}
示例2: AddMagickImageCollectionMethods
//===========================================================================================
private void AddMagickImageCollectionMethods(XElement annotation)
{
foreach (MethodInfo[] overloads in _GraphicsMagickNET.GetGroupedMagickImageCollectionMethods())
{
annotation.AddBeforeSelf(CreateElement(overloads));
}
}
示例3: InstallDashboard
// Partially taken from https://github.com/kipusoep/UrlTracker/blob/b2bc998adaae2f74779e1119fd7b1e97a3b71ed2/UI/Installer/UrlTrackerInstallerService.asmx.cs
public static bool InstallDashboard(string section, string caption, string control)
{
bool result = false;
try
{
string dashboardConfig;
string dashboardConfigPath = HttpContext.Current.Server.MapPath("~/config/dashboard.config");
using (StreamReader streamReader = File.OpenText(dashboardConfigPath))
dashboardConfig = streamReader.ReadToEnd();
if (string.IsNullOrEmpty(dashboardConfig))
throw new Exception("Unable to add dashboard: Couldn't read current ~/config/dashboard.config, permissions issue?");
XDocument dashboardDoc = XDocument.Parse(dashboardConfig, LoadOptions.PreserveWhitespace);
if (dashboardDoc == null)
throw new Exception("Unable to add dashboard: Unable to parse current ~/config/dashboard.config file, invalid XML?");
XElement dashBoardElement = dashboardDoc.Element("dashBoard");
if (dashBoardElement == null)
throw new Exception("Unable to add dashboard: dashBoard element not found in ~/config/dashboard.config file");
List<XElement> sectionElements = dashBoardElement.Elements("section").ToList();
if (sectionElements == null || !sectionElements.Any())
throw new Exception("Unable to add dashboard: No section elements found in ~/config/dashboard.config file");
XElement existingSectionElement = sectionElements.SingleOrDefault(x => x.Attribute("alias") != null && x.Attribute("alias").Value == section);
if (existingSectionElement == null)
throw new Exception(string.Format("Unable to add dashboard: '{0}' section not found in ~/config/dashboard.config", section));
List<XElement> tabs = existingSectionElement.Elements("tab").ToList();
if (!tabs.Any())
throw new Exception(string.Format("Unable to add dashboard: No existing tabs found within the '{0}' section", section));
List<XElement> existingTabs = tabs.Where(x => x.Attribute("caption").Value == caption).ToList();
if (existingTabs.Any())
{
foreach (XElement tab in existingTabs)
{
List<XElement> existingTabControls = tab.Elements("control").ToList();
if (existingTabControls.Any(x => x.Value == control))
return true;
}
}
XElement lastTab = tabs.Last();
XElement newTab = new XElement("tab");
newTab.Add(new XAttribute("caption", caption));
XElement newControl = new XElement("control");
newControl.Add(new XAttribute("addPanel", true));
newControl.SetValue(control);
newTab.Add(newControl);
newControl.AddBeforeSelf(string.Concat(Environment.NewLine, " "));
newControl.AddAfterSelf(string.Concat(Environment.NewLine, " "));
lastTab.AddAfterSelf(newTab);
lastTab.AddAfterSelf(string.Concat(Environment.NewLine, " "));
dashboardDoc.Save(dashboardConfigPath, SaveOptions.None);
result = true;
}
catch (Exception ex)
{
ExceptionHelper.LogExceptionMessage(typeof(DashboardHelper), ex);
}
return result;
}
示例4: InsertPredicate
public override void InsertPredicate(
XElement target, long id, ElementType type) {
var oldcode = Python3XmlToCode.Instance.Generate(target);
var code = "CoverageWriter.WritePredicate(" + id + "," + (int)type + ","
+ oldcode + ")";
var node = Python3CodeToXml.Instance.Generate(code)
.Descendants(target.Name)
.First();
target.AddBeforeSelf(node);
target.Remove();
}
示例5: CreateDocumentVerbose
// <?xml version="1.0"?>
// <?order alpha ascending?>
// <art xmlns='urn:art-org:art'>
// <period name='Renaissance' xmlns:a='urn:art-org:artists'>
// <a:artist>Leonardo da Vinci</a:artist>
// <a:artist>Michelangelo</a:artist>
// <a:artist><![CDATA[Donatello]]></a:artist>
// </period>
// <!-- 在此处插入 period -->
// </art>
public static XDocument CreateDocumentVerbose()
{
XNamespace nsArt = "urn:art-org:art";
XNamespace nsArtists = "urn:art-org:artists";
// 创建文档
XDocument document = new XDocument();
// 创建 xml 声明,并在
// 文档中对其进行设置
document.Declaration = new XDeclaration("1.0", null, null);
// 创建 art 元素,并将其
// 添加到文档中
XElement art = new XElement(nsArt + "art");
document.Add(art);
// 创建顺序处理指令,并将其
// 添加到 art 元素之前
XProcessingInstruction pi = new XProcessingInstruction("order", "alpha ascending");
art.AddBeforeSelf(pi);
// 创建 period 元素,并将其
// 添加到 art 元素中
XElement period = new XElement(nsArt + "period");
art.Add(period);
// 向 period 元素中添加 name 特性
period.SetAttributeValue("name", "Renaissance");
// 创建命名空间声明 xmlns:a,并将其
// 添加到 period 元素中
XAttribute nsdecl = new XAttribute(XNamespace.Xmlns + "a", nsArtists);
period.Add(nsdecl);
// 创建 artist 元素和
// 基础文本节点
period.SetElementValue(nsArtists + "artist", "Michelangelo");
XElement artist = new XElement(nsArtists + "artist", "Leonardo ", "da ", "Vinci");
period.AddFirst(artist);
artist = new XElement(nsArtists + "artist");
period.Add(artist);
XText cdata = new XText("Donatello");
artist.Add(cdata);
// 创建注释,并将其
// 添加到 art 元素中
XComment comment = new XComment("insert period here");
art.Add(comment);
return document;
}
示例6: ReplaceValues
private void ReplaceValues(XElement dynamicRow)
{
var readers = DataReader.GetReaders(TableTag.ItemsSource).ToList();
for (var index = 0; index < readers.Count(); index++)
{
var currentRow = new XElement(dynamicRow);
var tableElements = TableTag.MakeTableElementCallback(currentRow);
this.ProcessElements(tableElements, readers[index], index+1, null, true);
dynamicRow.AddBeforeSelf(currentRow);
}
dynamicRow.Remove();
}
示例7: InsertPredicate
public override void InsertPredicate(XElement target, long id, ElementType type) {
var node = new XElement("call", new object[] {
new XElement("nil"),
new XElement("Symbol", "branch"),
new XElement("lit", new[] {
new XElement("Fixnum", id),
}),
new XElement("lit", new[] {
new XElement("Fixnum", (int)type),
}),
target,
});
target.AddBeforeSelf(node);
target.Remove();
}
示例8: AddTof
public static void AddTof(WordprocessingDocument doc, XElement addBefore, string switches, int? rightTabPos)
{
UpdateFontTablePart(doc);
UpdateStylesPartForTof(doc);
UpdateStylesWithEffectsPartForTof(doc);
if (rightTabPos == null)
rightTabPos = 9350;
// {0} rightTabPosition (default = 9350)
// {1} switches
string xmlString =
@"<w:p xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:pPr>
<w:pStyle w:val='TableofFigures'/>
<w:tabs>
<w:tab w:val='right' w:leader='dot' w:pos='{0}'/>
</w:tabs>
<w:rPr>
<w:noProof/>
</w:rPr>
</w:pPr>
<w:r>
<w:fldChar w:fldCharType='begin' dirty='true'/>
</w:r>
<w:r>
<w:instrText xml:space='preserve'> {1} </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType='separate'/>
</w:r>
<w:r>
<w:fldChar w:fldCharType='end'/>
</w:r>
</w:p>";
XElement paragraph = XElement.Parse(String.Format(xmlString, rightTabPos, switches));
XDocument mainXDoc = doc.MainDocumentPart.GetXDocument();
addBefore.AddBeforeSelf(paragraph);
doc.MainDocumentPart.PutXDocument();
XDocument settingsXDoc = doc.MainDocumentPart.DocumentSettingsPart.GetXDocument();
XElement updateFields = settingsXDoc.Descendants(W.updateFields).FirstOrDefault();
if (updateFields != null)
updateFields.Attribute(W.val).Value = "true";
else
{
updateFields = new XElement(W.updateFields,
new XAttribute(W.val, "true"));
settingsXDoc.Root.Add(updateFields);
}
doc.MainDocumentPart.DocumentSettingsPart.PutXDocument();
}
示例9: NodeAddBeforeSelf
/// <summary>
/// Tests AddBeforeSelf on Node.
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
//[Variation(Desc = "NodeAddBeforeSelf")]
public void NodeAddBeforeSelf()
{
XElement parent = new XElement("parent");
XElement child = new XElement("child");
parent.Add(child);
XElement sibling1 = new XElement("sibling1");
XComment sibling2 = new XComment("sibling2");
XText sibling3 = new XText("sibling3");
child.AddBeforeSelf(sibling1);
Validate.EnumeratorDeepEquals(parent.Nodes(), new XNode[] { sibling1, child });
child.AddBeforeSelf(sibling2, sibling3);
Validate.EnumeratorDeepEquals(
parent.Nodes(),
new XNode[] { sibling1, sibling2, sibling3, child });
}
示例10: AddToc
public static void AddToc(WordprocessingDocument doc, XElement addBefore, string switches, string title,
int? rightTabPos)
{
UpdateFontTablePart(doc);
UpdateStylesPartForToc(doc);
UpdateStylesWithEffectsPartForToc(doc);
if (title == null)
title = "Contents";
if (rightTabPos == null)
rightTabPos = 9350;
// {0} tocTitle (default = "Contents")
// {1} rightTabPosition (default = 9350)
// {2} switches
String xmlString =
@"<w:sdt xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'>
<w:sdtPr>
<w:docPartObj>
<w:docPartGallery w:val='Table of Contents'/>
<w:docPartUnique/>
</w:docPartObj>
</w:sdtPr>
<w:sdtEndPr>
<w:rPr>
<w:rFonts w:asciiTheme='minorHAnsi' w:cstheme='minorBidi' w:eastAsiaTheme='minorHAnsi' w:hAnsiTheme='minorHAnsi'/>
<w:color w:val='auto'/>
<w:sz w:val='22'/>
<w:szCs w:val='22'/>
<w:lang w:eastAsia='en-US'/>
</w:rPr>
</w:sdtEndPr>
<w:sdtContent>
<w:p>
<w:pPr>
<w:pStyle w:val='TOCHeading'/>
</w:pPr>
<w:r>
<w:t>{0}</w:t>
</w:r>
</w:p>
<w:p>
<w:pPr>
<w:pStyle w:val='TOC1'/>
<w:tabs>
<w:tab w:val='right' w:leader='dot' w:pos='{1}'/>
</w:tabs>
<w:rPr>
<w:noProof/>
</w:rPr>
</w:pPr>
<w:r>
<w:fldChar w:fldCharType='begin' w:dirty='true'/>
</w:r>
<w:r>
<w:instrText xml:space='preserve'> {2} </w:instrText>
</w:r>
<w:r>
<w:fldChar w:fldCharType='separate'/>
</w:r>
</w:p>
<w:p>
<w:r>
<w:rPr>
<w:b/>
<w:bCs/>
<w:noProof/>
</w:rPr>
<w:fldChar w:fldCharType='end'/>
</w:r>
</w:p>
</w:sdtContent>
</w:sdt>";
XElement sdt = XElement.Parse(String.Format(xmlString, title, rightTabPos, switches));
XDocument mainXDoc = doc.MainDocumentPart.GetXDocument();
addBefore.AddBeforeSelf(sdt);
doc.MainDocumentPart.PutXDocument();
XDocument settingsXDoc = doc.MainDocumentPart.DocumentSettingsPart.GetXDocument();
XElement updateFields = settingsXDoc.Descendants(W.updateFields).FirstOrDefault();
if (updateFields != null)
updateFields.Attribute(W.val).Value = "true";
else
{
updateFields = new XElement(W.updateFields,
new XAttribute(W.val, "true"));
settingsXDoc.Root.Add(updateFields);
}
doc.MainDocumentPart.DocumentSettingsPart.PutXDocument();
}
示例11: transform_selection
public static void transform_selection(XElement xml) {
var sels = xml.Descendants(exFile.lm + "selection").ToArray();
//html titles se daji pred selection, BT 2149
var htmlTits = sels.SelectMany(s => s.Attributes("title_html")).ToArray();
Dictionary<string, XElement> htmlTitles = null;
if (htmlTits.Length > 0) {
htmlTitles = xml.Descendants().Select(el => new { el, id = el.AttributeValue("id") }).Where(a => a.id != null).ToDictionary(a => a.id, a => a.el);
}
XAttribute attrBuf;
foreach (var sel in sels) {
bool isRadio = sel.AttributeValue("type") == "radioButton";
if (isRadio) {
string title = sel.AttributeValue("title");
string htmlTitle = sel.AttributeValue("title_html");
sel.AddBeforeSelf(new XComment(sel.ToString()));
XElement newSel;
sel.AddBeforeSelf(
new XElement(exFile.lm + "control",
// string.IsNullOrEmpty(title) ? null : new XElement(exFile.html + "header-prop", new XElement(exFile.html + "h4", title)),
string.IsNullOrEmpty(title) ? null : new XElement(exFile.html + "h4", title),
newSel = new XElement(exFile.html + "single-choice",
(attrBuf = sel.Attribute("id")) == null ? null : new XAttribute("id", attrBuf.Value),
sel.Elements().Select(cb =>
new XElement(exFile.html + "radio-button",
(attrBuf = cb.Attribute("id")) == null ? null : new XAttribute("id", attrBuf.Value),
cb.AttributeValue("title"),
cb.AttributeValue("init_value") == "Checked" ? new XAttribute("init-value", "true") : null,
(attrBuf = cb.Attribute("correct")) == null ? null : new XAttribute("correct-value", attrBuf.Value)
)))));
if (htmlTitle != null) {
htmlTitles[htmlTitle].Remove();
newSel.AddBeforeSelf(htmlTitles[htmlTitle]);
}
var isEx = sel.Elements().Any(cb => new string[] { "true", "1" }.Contains(cb.AttributeValue("example")));
var isInit = sel.Elements().Any(cb => cb.AttributeValue("init_value") == "Checked");
if (isEx) {
newSel.Add(isInit ? new XAttribute("read-only", "true") : new XAttribute("skip-evaluation", "true"));
}
} else {
string title = sel.AttributeValue("title");
string htmlTitle = sel.AttributeValue("title_html");
sel.AddBeforeSelf(new XComment(sel.ToString()));
var id = sel.AttributeValue("id");
//XElement newSel;
sel.AddBeforeSelf(
new XElement(exFile.lm + "control",
string.IsNullOrEmpty(title) ? null : new XElement(exFile.html + "h4", title),
htmlTitle == null ? null : htmlTitles[htmlTitle],
sel.Elements().Select(cb =>
new XElement(exFile.html + "check-item",
new XAttribute("text-type", "no"),
(attrBuf = cb.Attribute("id")) == null ? null : new XAttribute("id", attrBuf.Value),
cb.AttributeValue("title"),
cb.AttributeValue("eval_group") == "And" && !string.IsNullOrEmpty(id) ? new XAttribute("eval-group", "and-" + id) : null,
cb.AttributeValue("init_value") == "Checked" ? new XAttribute("init-value", "True") : null,
(attrBuf = cb.Attribute("correct")) == null ? null : new XAttribute("correct-value", attrBuf.Value)
))));
if (htmlTitle != null) htmlTitles[htmlTitle].Remove();
}
sel.Remove();
}
//if (htmlTitles != null) htmlTitles.Values.Remove();
}
示例12: DoInlineImport
void DoInlineImport(XElement import, InlineImport inlineImport)
{
var importPath = ExpandPath(SourceDirectory, import.Attribute("Project").Value);
var inlinedDoc = XDocument.Load(importPath);
RelocateImports(Path.GetDirectoryName(importPath), inlinedDoc);
var project = inlinedDoc.Root;
List<XNode> filteredNodes = new List<XNode>();
bool inSample = true;
foreach (var node in project.Nodes())
{
if (node is XComment)
{
var comment = (XComment)node;
if (comment.Value.Contains("[[NOT IN SAMPLE]]"))
{
inSample = false;
continue;
}
else if (comment.Value.Contains("[[IN SAMPLE]]"))
{
inSample = true;
continue;
}
}
if (inSample)
filteredNodes.Add(node);
}
import.AddBeforeSelf(filteredNodes);
if (inlineImport.Elements.Count > 0)
{
import.AddBeforeSelf(inlineImport.Elements);
}
import.Remove();
}
示例13: ReplaceEnums
//===========================================================================================
private void ReplaceEnums(XElement annotation)
{
foreach (Type enumType in _GraphicsMagickNET.Enums)
{
annotation.AddBeforeSelf(CreateEnumElement(enumType));
}
annotation.Remove();
}
示例14: NodeAddBeforeSelf
public void NodeAddBeforeSelf()
{
XElement parent = new XElement("parent");
XElement child = new XElement("child");
parent.Add(child);
XElement sibling1 = new XElement("sibling1");
XComment sibling2 = new XComment("sibling2");
XText sibling3 = new XText("sibling3");
child.AddBeforeSelf(sibling1);
Assert.Equal(new XNode[] { sibling1, child }, parent.Nodes(), XNode.EqualityComparer);
child.AddBeforeSelf(sibling2, sibling3);
Assert.Equal(new XNode[] { sibling1, sibling2, sibling3, child }, parent.Nodes(), XNode.EqualityComparer);
}
示例15: ReplaceDrawables
private void ReplaceDrawables(XElement annotation)
{
foreach (ConstructorInfo[] constructors in _Types.GetDrawables())
{
annotation.AddBeforeSelf(CreateElement(constructors));
}
annotation.Remove();
}