本文整理汇总了C#中System.Xml.Linq.XElement.Add方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.Add方法的具体用法?C# XElement.Add怎么用?C# XElement.Add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToXml
public static XElement ToXml(ConvolutionFilter filter)
{
var res = new XElement(TAG_NAME,
new XAttribute("divisor", CommonFormatter.Format(filter.Divisor)),
new XAttribute("bias", CommonFormatter.Format(filter.Bias))
);
var xMatrix = new XElement("matrix");
for (var y = 0; y < filter.MatrixY; y++) {
var xRow = new XElement("r");
for (var x = 0; x < filter.MatrixX; x++) {
var xCol = new XElement("c") { Value = CommonFormatter.Format(filter.Matrix[y, x]) };
xRow.Add(xCol);
}
xMatrix.Add(xRow);
}
res.Add(xMatrix);
res.Add(new XElement("color", XColorRGBA.ToXml(filter.DefaultColor)));
if (filter.Reserved != 0) {
res.Add(new XAttribute("reserved", filter.Reserved));
}
res.Add(new XAttribute("clamp", CommonFormatter.Format(filter.Clamp)));
res.Add(new XAttribute("preserveAlpha", CommonFormatter.Format(filter.PreserveAlpha)));
return res;
}
示例2: Serialize
public override XElement Serialize()
{
XElement thisElement = new XElement(GetType().Name);
thisElement.Add(insideEquation.Serialize());
thisElement.Add(outerEquation.Serialize());
return thisElement;
}
示例3: CreateFolders
public void CreateFolders(Project currentProject, string schedule, string projectName, string relativePath)
{
//Create a File under Properties Folder which will contain information about all WebJobs
//https://github.com/ligershark/webjobsvs/issues/6
// Check if the WebApp is C# or VB
string dir = GetProjectDirectory(currentProject);
var propertiesFolderName = "Properties";
if (currentProject.CodeModel.Language == CodeModelLanguageConstants.vsCMLanguageVB)
{
propertiesFolderName = "My Project";
}
DirectoryInfo info = new DirectoryInfo(Path.Combine(dir, propertiesFolderName));
string readmeFile = Path.Combine(info.FullName, "WebJobs.xml");
// Copy File if it does not exit
if (!File.Exists(readmeFile))
AddReadMe(readmeFile);
//Add a WebJob info to it
XDocument doc = XDocument.Load(readmeFile);
XElement root = new XElement("WebJob");
root.Add(new XAttribute("Project", projectName));
root.Add(new XAttribute("RelativePath", relativePath));
root.Add(new XAttribute("Schedule", schedule));
doc.Element("WebJobs").Add(root);
doc.Save(readmeFile);
currentProject.ProjectItems.AddFromFile(readmeFile);
}
示例4: InjectData
/// <summary>
/// Injects Calibre's metadata into XHTML element (for metadata part)
/// </summary>
/// <param name="metadata"></param>
public void InjectData(XElement metadata)
{
if (!string.IsNullOrEmpty(SeriesName))
{
XElement serie = new XElement(MetaName);
serie.Add(new XAttribute("name", "calibre:series"));
serie.Add(new XAttribute("content", SeriesName));
metadata.Add(serie);
}
if (SeriesIndex != 0)
{
XElement serieIndex = new XElement(MetaName);
serieIndex.Add(new XAttribute("name", "calibre:series_index"));
serieIndex.Add(new XAttribute("content", SeriesIndex));
metadata.Add(serieIndex);
}
if (!string.IsNullOrEmpty(TitleForSort))
{
XElement title4Sort = new XElement(MetaName);
title4Sort.Add(new XAttribute("name", "calibre:title_sort"));
title4Sort.Add(new XAttribute("content", TitleForSort));
metadata.Add(title4Sort);
}
XElement date = new XElement(MetaName);
date.Add(new XAttribute("name", "calibre:timestamp"));
date.Add(new XAttribute("content", DateTime.UtcNow.ToString("O")));
metadata.Add(date);
}
示例5: Format
public XElement Format(Scenario scenario, int id)
{
var header = new XElement(
this.xmlns + "div",
new XAttribute("class", "scenario-heading"),
new XElement(this.xmlns + "h2", scenario.Name));
var tags = RetrieveTags(scenario);
if (tags.Length > 0)
{
var paragraph = new XElement(this.xmlns + "p", CreateTagElements(tags.OrderBy(t => t).ToArray(), this.xmlns));
paragraph.Add(new XAttribute("class", "tags"));
header.Add(paragraph);
}
header.Add(this.htmlDescriptionFormatter.Format(scenario.Description));
return new XElement(
this.xmlns + "li",
new XAttribute("class", "scenario"),
this.htmlImageResultFormatter.Format(scenario),
header,
new XElement(
this.xmlns + "div",
new XAttribute("class", "steps"),
new XElement(
this.xmlns + "ul",
scenario.Steps.Select(step => this.htmlStepFormatter.Format(step)))));
}
示例6: AddNextObxElement
public void AddNextObxElement(string value, XElement document, string observationResultStatus)
{
XElement obxElement = new XElement("OBX");
XElement obx01Element = new XElement("OBX.1");
XElement obx0101Element = new XElement("OBX.1.1", this.m_ObxCount.ToString());
obx01Element.Add(obx0101Element);
obxElement.Add(obx01Element);
XElement obx02Element = new XElement("OBX.2");
XElement obx0201Element = new XElement("OBX.2.1", "TX");
obx02Element.Add(obx0201Element);
obxElement.Add(obx02Element);
XElement obx03Element = new XElement("OBX.3");
XElement obx0301Element = new XElement("OBX.3.1", "&GDT");
obx03Element.Add(obx0301Element);
obxElement.Add(obx03Element);
XElement obx05Element = new XElement("OBX.5");
XElement obx0501Element = new XElement("OBX.5.1", value);
obx05Element.Add(obx0501Element);
obxElement.Add(obx05Element);
XElement obx11Element = new XElement("OBX.11");
XElement obx1101Element = new XElement("OBX.11.1", observationResultStatus);
obx11Element.Add(obx1101Element);
obxElement.Add(obx11Element);
this.m_ObxCount++;
document.Add(obxElement);
}
示例7: Build
public static string Build()
{
bool value = false;
string message = "Fail!";
XElement result = new XElement("Result");
try
{
using (PlayerBussiness db = new PlayerBussiness())
{
BestEquipInfo[] infos = db.GetCelebByDayBestEquip();
foreach (BestEquipInfo info in infos)
{
result.Add(FlashUtils.CreateBestEquipInfo(info));
}
value = true;
message = "Success!";
}
}
catch (Exception ex)
{
log.Error("Load CelebByDayBestEquip is fail!", ex);
}
result.Add(new XAttribute("value", value));
result.Add(new XAttribute("message", message));
return csFunction.CreateCompressXml(result, "CelebForBestEquip", false);
}
示例8: ToPhysical
public System.Xml.Linq.XElement ToPhysical(System.Xml.Linq.XElement udsService)
{
string name = udsService.Attribute("Name").Value;
XElement x = new XElement("Service", new XAttribute("Name", name));
XElement prop = new XElement("Property", new XAttribute("Name", "Definition"));
x.Add(prop);
XElement serv = new XElement("Service");
prop.Add(serv);
XElement sd = new XElement("ServiceDescription");
serv.Add(sd);
XElement handler = new XElement("Handler", new XAttribute("ExecType", "RemoteComponent"));
sd.Add(handler);
XElement udsDefinition = udsService.Element("Definition");
foreach (XElement e in udsDefinition.Elements())
sd.Add(e);
XElement usage = new XElement("Usage");
sd.Add(usage);
XElement sh = new XElement("ServiceHelp");
sh.Add(new XElement("Description"));
sh.Add(new XElement("RequestSDDL"));
sh.Add(new XElement("ResponseSDDL"));
sh.Add(new XElement("Errors"));
sh.Add(new XElement("RelatedDocumentServices"));
sh.Add(new XElement("Samples"));
serv.Add(sh);
return x;
}
示例9: Main
public static void Main()
{
var context = new GeographyEntities();
var countries = context.Countries;
var countriesQuery = countries
.Where(c => c.Monasteries.Any())
.OrderBy(c => c.CountryName)
.Select(c => new
{
c.CountryName,
Monasteries = c.Monasteries
.OrderBy(m => m.Name)
.Select(m => m.Name)
});
// Build the output XML
var xmlMonasteries = new XElement("monasteries");
foreach (var country in countriesQuery)
{
var xmlCountry = new XElement("country");
xmlCountry.Add(new XAttribute("name", country.CountryName));
foreach (var monastery in country.Monasteries)
{
xmlCountry.Add(new XElement("monastery", monastery));
}
xmlMonasteries.Add(xmlCountry);
}
Console.WriteLine(xmlMonasteries);
var xmlDoc = new XDocument(xmlMonasteries);
xmlDoc.Save(@"..\..\monasteries.xml");
}
示例10: Main
static void Main(string[] args)
{
var db = new GeographyEntities();
var countries = db.Countries
.OrderBy(c => c.CountryName)
.Select(c => new
{
coutryName = c.CountryName,
monasteries = c.Monasteries.OrderBy(m => m.Name).Select(m => m.Name)
}).ToList();
XElement root = new XElement("monasteries");
foreach (var country in countries)
{
if (country.monasteries.Count() != 0)
{
var xmlCountry = new XElement("country");
xmlCountry.Add(new XAttribute("name", country.coutryName));
foreach (var xmlMonasteries in country.monasteries)
{
xmlCountry.Add(new XElement("monastery", xmlMonasteries));
}
root.Add(xmlCountry);
}
}
var xmlDoc = new XDocument(root);
xmlDoc.Save("../../monasteries.xml");
}
示例11: ToXML
public XNode ToXML()
{
XElement xPoem = new XElement(Fb2Const.fb2DefaultNamespace + Fb2PoemElementName);
if (!string.IsNullOrEmpty(ID))
{
xPoem.Add(new XAttribute("id", ID));
}
if (!string.IsNullOrEmpty(Lang))
{
xPoem.Add(new XAttribute(XNamespace.Xml + "lang", Lang));
}
if (Title != null)
{
xPoem.Add(Title.ToXML());
}
foreach (EpigraphItem PoemEpigraph in Epigraphs)
{
xPoem.Add(PoemEpigraph.ToXML());
}
foreach (IFb2TextItem PoemStanza in content)
{
xPoem.Add(PoemStanza.ToXML());
}
foreach (TextAuthorItem TextAuthor in authors)
{
xPoem.Add(TextAuthor.ToXML());
}
if (Date != null)
{
xPoem.Add(Date.ToXML());
}
return xPoem;
}
示例12: ToXElement
/// <summary>
/// Writes out the assertion as an XElement.
/// </summary>
/// <param name="assertion">The assertion to create xml for.</param>
/// <returns>XElement</returns>
public static XElement ToXElement(this Saml2Assertion assertion)
{
if(assertion == null)
{
throw new ArgumentNullException(nameof(assertion));
}
var xml = new XElement(Saml2Namespaces.Saml2 + "Assertion",
new XAttribute(XNamespace.Xmlns + "saml2", Saml2Namespaces.Saml2Name),
new XAttribute("Version", assertion.Version),
new XAttribute("ID", assertion.Id.Value),
new XAttribute("IssueInstant",
assertion.IssueInstant.ToSaml2DateTimeString()),
new XElement(Saml2Namespaces.Saml2 + "Issuer", assertion.Issuer.Value));
if (assertion.Subject != null)
{
xml.Add(assertion.Subject.ToXElement());
}
if(assertion.Conditions != null)
{
xml.Add(assertion.Conditions.ToXElement());
}
if (assertion.Statements != null)
{
foreach (var statement in assertion.Statements)
{
xml.Add(statement.ToXElement());
};
}
return xml;
}
示例13: GetElements
public IEnumerable<XElement> GetElements(int tenant, string[] configs, IDataWriteOperator writer)
{
var xml = new List<XElement>();
var connectionKeys = new Dictionary<string, string>();
foreach (ConnectionStringSettings connectionString in GetConnectionStrings(configs))
{
//do not save the base, having the same provider and connection string is not to duplicate
//data, but also expose the ref attribute of repetitive bases for the correct recovery
var node = new XElement(connectionString.Name);
xml.Add(node);
var connectionKey = connectionString.ProviderName + connectionString.ConnectionString;
if (connectionKeys.ContainsKey(connectionKey))
{
node.Add(new XAttribute("ref", connectionKeys[connectionKey]));
}
else
{
connectionKeys.Add(connectionKey, connectionString.Name);
OnProgressChanged("Saving database " + connectionString.Name, -1);
node.Add(BackupDatabase(tenant, connectionString, writer));
OnProgressChanged("OK", 100);
}
}
return xml;
}
示例14: GenerateXmlElement
public XElement GenerateXmlElement()
{
var binding = new XElement("binding", new XAttribute("template", this.TileTemplate.ToString()));
if (!string.IsNullOrEmpty(Language))
binding.Add(new XAttribute("lang", XmlEncode(Language)));
if (Branding.HasValue)
binding.Add(new XAttribute("branding", XmlEncode(Branding.Value.ToString().ToLowerInvariant())));
if (!string.IsNullOrEmpty(BaseUri))
binding.Add(new XAttribute("baseUri", XmlEncode(BaseUri)));
if (AddImageQuery.HasValue)
binding.Add(new XAttribute("addImageQuery", AddImageQuery.Value.ToString().ToLowerInvariant()));
int idOn = 1;
if (Images != null)
{
foreach (var img in Images)
binding.Add(img.GenerateXmlElement(idOn++));
}
idOn = 1;
if (Texts != null)
{
foreach (var text in Texts)
binding.Add(text.GenerateXmlElement(idOn++));
}
return binding;
}
示例15: CreateXmlDocument
private static XDocument CreateXmlDocument(List<PhotographExportModel> photographs)
{
var root = new XElement("photographs");
XDocument photographsDoc = new XDocument(root);
foreach (var photo in photographs)
{
var photograph =
new XElement("photograph", new XAttribute("title", photo.Title),
new XElement("category", photo.CategoryName),
new XElement("link", photo.Link));
var equipment = new XElement("equipment");
equipment.Add(
new XElement("camera", photo.CameraModel,
new XAttribute("megapixels", photo.CameraMegaPixels)));
var lens = new XElement("lens", photo.LensModel);
if (photo.LensPrice != null)
{
lens.Add(new XAttribute("price", Math.Round(photo.LensPrice.Value, 2)));
}
equipment.Add(lens);
photograph.Add(equipment);
photographsDoc.Root.Add(photograph);
}
return photographsDoc;
}