本文整理汇总了C#中System.Xml.Linq.XElement.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.ToString方法的具体用法?C# XElement.ToString怎么用?C# XElement.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XElement
的用法示例。
在下文中一共展示了XElement.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public void Execute(ClientContext ctx, string listTitle, XElement schema, Action<Field> setAdditionalProperties = null)
{
var displayName = schema.Attribute("DisplayName").Value;
Logger.Verbose($"Started executing {nameof(CreateColumnOnList)} for column '{displayName}' on list '{listTitle}'");
var list = ctx.Web.Lists.GetByTitle(listTitle);
var fields = list.Fields;
ctx.Load(fields);
ctx.ExecuteQuery();
// if using internal names in code, remember to encode those before querying, e.g.,
// space character becomes "_x0020_" as described here:
// http://www.n8d.at/blog/encode-and-decode-field-names-from-display-name-to-internal-name/
// We don't use the internal name here because it's limited to 32 chacters. This means
// "Secondary site abcde" is the longest possible internal name when taken into account
// the "_x0020_" character. Using a longer name will truncate the internal name to 32
// characters. Thus querying on the complete, not truncated name, will always return no
// results which causes the field get created repetedly.
var field = fields.SingleOrDefault(f => f.Title == displayName);
if (field != null)
{
Logger.Warning($"Column '{displayName}' already on list {listTitle}");
return;
}
var newField = list.Fields.AddFieldAsXml(schema.ToString(), true, AddFieldOptions.DefaultValue);
ctx.Load(newField);
ctx.ExecuteQuery();
if (setAdditionalProperties != null)
{
setAdditionalProperties(newField);
newField.Update();
}
}
示例2: Validate
protected override XElement Validate(XElement item)
{
// Validate with XSD
XElement xsdErrors = this.ValidateXSD(item, HttpContext.Current.Server.MapPath(@"~\Xslt\Senior\Senior.xsd"));
if (xsdErrors != null && xsdErrors.Elements("Error").Count() > 0)
{
return xsdErrors;
}
// Validate with Stored Proc
string result = string.Empty;
using (Persistence oDB = new Persistence())
{
Persistence.ParameterCollection parameters = new Persistence.ParameterCollection();
parameters.Add("InputXml");
parameters[0].Value = item.ToString();
oDB.Execute("Masters_ConnectionString", "ValidateSeniorData", parameters, out result);
}
if (!string.IsNullOrEmpty(result))
{
XElement spErrors = XElement.Parse(result);
spErrors.Elements("Error").Where(e => string.IsNullOrEmpty(e.Value)).Remove();
if (spErrors.Elements("Error").Count() > 0)
{
return spErrors;
}
}
// SUCCESS!
return null;
}
示例3: GetJohnDeerePartInfoAndSubmit
public void GetJohnDeerePartInfoAndSubmit(XElement SKUParts)
{
string info = "";
bool IsFailed = false;
try
{
info = GetJohnDeerePartInfo(SKUParts);
//var fileBytes = Encoding.Default.GetBytes(info);
//string acsNamespace = HartvilleToolConfigManager.GetSetting("JohnDeere.Biztalk.acsNamespace");
//string issuerName = HartvilleToolConfigManager.GetSetting("JohnDeere.Biztalk.issuerName");
//string issuerKey = HartvilleToolConfigManager.GetSetting("JohnDeere.Biztalk.issuerKey");
//string runtimeAddress = HartvilleToolConfigManager.GetSetting("JohnDeere.Biztalk.runtimeAddress");
//string contentType = "application/xml";
//// Trace.TraceInformation("Prepare for sending to Biztalk");
//MessageSender.SendMessage(acsNamespace,
// issuerName, issuerKey, runtimeAddress,
// fileBytes, contentType);
InsertResultIntoSQL(info);
}
catch(Exception ex) {
IsFailed = true;
HartvilleToolConfigManager.NotifyEmailError("Error GetJohnDeerePartInfo raw-WCF" + ex.Message, SKUParts.ToString() + Environment.NewLine + info);
}
LogRequestIntoDatabase("GetJohnDeerePartInfo", SKUParts.ToString(), info, IsFailed);
}
示例4: ParseRDFItem
/// <summary>
/// RSS version 1.0
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
private RssSchema ParseRDFItem(XElement item)
{
var rssItem = ParseItem(item);
rssItem.PublishDate = item.GetSafeElementDate("date", NsRdfElementsNamespaceUri);
string image = item.GetSafeElementString("image");
if (string.IsNullOrEmpty(image))
{
image = item.GetImage();
}
if (string.IsNullOrEmpty(image) && item.ToString().Contains("media:thumbnail"))
{
XNamespace ns = "http://search.yahoo.com/mrss/";
var element = item.Elements(ns + "thumbnail").Last();
image = element.Attribute("url").Value;
}
if (string.IsNullOrEmpty(image) && item.ToString().Contains("thumbnail"))
{
image = item.GetSafeElementString("thumbnail");
}
rssItem.ImageUrl = image;
return rssItem;
}
示例5: PrintXml
private static void PrintXml(XElement xml){
Console.WriteLine(xml.ToString());
Console.WriteLine();
Console.WriteLine("---------------------------");
Console.WriteLine();
Console.WriteLine(xml.ToString().Replace("\"", "\"\""));
}
示例6: formulaVector
public Scientrace.Vector formulaVector(Scientrace.Vector aVector, XElement xformula)
{
string f_x = "x";
string f_y = "y";
string f_z = "z";
if (xformula.Attribute("xyz") != null) {
try {
string xyz = xformula.Attribute("xyz").Value;
char[] delimiterChars = { ';', '\t' };
string[] elements = xyz.Split(delimiterChars);
if (elements.Length !=3) {
throw new XMLException("Element "+xformula.ToString()+" has \""+elements.Length+ "\" != 3 valid vector elements. ");
}
f_x=elements[0];
f_y=elements[1];
f_z=elements[2];
} catch { throw new XMLException("Formula "+xformula.ToString()+" does not have proper parameters for {xyz} attribute (can't parse {"+xformula.Attribute("xyz").Value.ToString()+"}. Perhaps incorrect use of PreProcess variables or decimal separators?)."); }
} // attribute "xyz"
f_x = this.getXStringByName(xformula, "x", f_x);
f_y = this.getXStringByName(xformula, "y", f_y);
f_z = this.getXStringByName(xformula, "z", f_z);
Dictionary<string, object> replace_vectors = new Dictionary<string, object>(){{"x", (decimal)aVector.x}, {"y", (decimal)aVector.y}, {"z", (decimal)aVector.z} };
return new Scientrace.Vector(
Scientrace.MathStrings.solveString(f_x, replace_vectors),
Scientrace.MathStrings.solveString(f_y, replace_vectors),
Scientrace.MathStrings.solveString(f_z, replace_vectors)
);
}
示例7: Trans
private void Trans(XElement serializedExpression)
{
serializedExpression.Save("beforeTransit.xml");
Console.WriteLine("beforeTransit:");
Console.WriteLine(serializedExpression.ToString());
Transit(serializedExpression);
Console.WriteLine("afterTransit:");
Console.WriteLine(serializedExpression.ToString());
serializedExpression.Save("afterTransit.xml");
}
示例8: ConstructorShould_Load_Project_File_Content_Into_Member
public void ConstructorShould_Load_Project_File_Content_Into_Member()
{
XElement fileContentAsXml = new XElement("project", new XElement("project_name", PROJECT_NAME));
File.WriteAllText(projectFilePath, fileContentAsXml.ToString());
ProjectFileReader pfr = new ProjectFileReader(projectFilePath);
Assert.AreEqual(fileContentAsXml.ToString(), pfr.ProjectFileContent);
}
示例9: UpdatePaymentRequest
public long UpdatePaymentRequest(XElement xml)
{
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("UpdatePaymentRequest {0}", xml));
}
long batchControlLogId = 0;
using (SqlConnection conn = new SqlConnection(this.GeniusXConnectionString))
{
conn.Open();
// insert record in BatchControllog (Status = In Progress)
batchControlLogId = this.AddBatchEntry(BatchControlConstant.BatchType.Custom, "Description", xml.ToString(), conn);
try
{
// update Paymenet request
using (SqlCommand cmd = new SqlCommand("UpdatePaymentRequestAXA", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@PaymentRequests", SqlDbType.Xml).Value = xml.ToString();
cmd.ExecuteScalar();
}
// update BatchControlLog (Status = completed, CompletionStatus = Clear)
this.UpdateBatchStatus(batchControlLogId, BatchControlConstant.BatchStatus.Completed, BatchControlConstant.CompletionStatus.Clear, conn);
}
catch (Exception ex)
{
// insert record into BatchErrorLogHeader
// add error detail into BatchErrorLogDetail
this.AddErrorLog(batchControlLogId, BatchControlConstant.MessageLevel.Error, ex.Message, string.Empty, conn);
// update BatchControlLog (Status = completed, CompletionStatus= Errors)
this.UpdateBatchStatus(batchControlLogId, BatchControlConstant.BatchStatus.Completed, BatchControlConstant.CompletionStatus.Errors, conn);
logger.Error(string.Format("UpdatePaymentRequest - {0}", ex.Message));
return batchControlLogId;
}
}
if (logger.IsDebugEnabled)
{
logger.Debug(string.Format("UpdatePaymentRequest {0} => returns: {1}", xml,batchControlLogId));
}
return 0;
}
示例10: TestAssignValue
public void TestAssignValue()
{
var address = new XElement("address",
new XElement("street", "1st street"),
new XElement("city", "2nd city"));
var street = address.Element("street");
street.Value = "88";
Assert.AreEqual("<address><street>88</street><city>2nd city</city></address>", address.ToString(SaveOptions.DisableFormatting));
// -------------- set value on parent will replace all its children elements
address.Value = "replaced";
Assert.AreEqual("<address>replaced</address>", address.ToString(SaveOptions.DisableFormatting));
}
示例11: FromXml
public static PaymentMethod FromXml(XElement element)
{
if (element == null)
{
return null;
}
var ret = new PaymentMethod(element.ToString());
ret.Token = element.GetStringChild("token");
ret.Number = element.GetStringChild("number");
ret.StorageState = element.GetStringChild("storage_state");
ret.FirstName = element.GetStringChild("first_name");
ret.LastName = element.GetStringChild("last_name");
ret.CreatedAt = DateTime.Parse(element.GetStringChild("created_at"));
ret.ExpirationMonth = int.Parse(element.GetStringChild("month"));
ret.ExpirationYear = int.Parse(element.GetStringChild("year"));
ret.CardType = element.GetStringChild("card_type");
ret.Address1 = element.GetStringChild("address1");
ret.Address2 = element.GetStringChild("address2");
ret.City = element.GetStringChild("city");
ret.State = element.GetStringChild("state");
ret.Zip = element.GetStringChild("zip");
ret.Country = element.GetStringChild("country");
return ret;
}
示例12: ProcessRequest
public void ProcessRequest(HttpContext context)
{
bool value = false;
string message = "Fail!";
XElement result = new XElement("Result");
try
{
int userid = int.Parse(context.Request.Params["ID"]);
using (PlayerBussiness db = new PlayerBussiness())
{
ItemInfo[] items = db.GetUserItem(userid);
foreach (ItemInfo item in items)
{
result.Add(Road.Flash.FlashUtils.CreateGoodsInfo(item));
}
}
value = true;
message = "Success!";
}
catch (Exception ex)
{
log.Error("LoadUserItems", ex);
}
result.Add(new XAttribute("value", value));
result.Add(new XAttribute("message", message));
context.Response.ContentType = "text/plain";
context.Response.Write(result.ToString(false));
}
示例13: Compare
public void Compare(XElement expected, XElement actual)
{
this.UpdateSchemasForUseStrongSpatialTypes(expected);
this.UpdateSchemasForUseStrongSpatialTypes(actual);
this.UpdateSchemaAliasToSchemaNamepsace(expected);
this.UpdateSchemaAliasToSchemaNamepsace(actual);
this.UpdatePrimitiveTypeNameForEdmFullName(expected);
this.UpdatePrimitiveTypeNameForEdmFullName(actual);
this.CompensateDefaultFacets(expected);
this.CompensateDefaultFacets(actual);
this.CompensateSpatialTypeSrid(expected);
this.CompensateSpatialTypeSrid(actual);
XElement sortedExpected = this.csdlSorter.SortCsdl(expected);
XElement sortedActual = this.csdlSorter.SortCsdl(actual);
Console.WriteLine("Sorted Expected: " + expected.ToString());
Console.WriteLine("Sorted Actual: " + sortedActual.ToString());
Assert.AreEqual(sortedExpected.ToString(), sortedActual.ToString(), "Csdl not equal!");
}
示例14: belEncerramentoMDFe
public belEncerramentoMDFe(PesquisaManifestosModel objPesquisa, string cUF, string cMun)
{
this.objPesquisa = objPesquisa;
XNamespace pf = "http://www.portalfiscal.inf.br/mdfe";
XContainer envCTe = new XElement(pf + "evEncMDFe",
new XElement(pf + "descEvento", "Encerramento"),
new XElement(pf + "nProt", objPesquisa.protocolo),
new XElement(pf + "dtEnc", daoUtil.GetDateServidor().ToString("yyyy-MM-dd")),
new XElement(pf + "cUF", cUF),
new XElement(pf + "cMun", cMun.Trim()));
XmlDocument xmlCanc = new XmlDocument();
xmlCanc.LoadXml(envCTe.ToString());
string sPath = Pastas.PROTOCOLOS + objPesquisa.protocolo + "evEnc.xml";
if (File.Exists(sPath))
File.Delete(sPath);
xmlCanc.Save(sPath);
try
{
belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/mdfe", Pastas.SCHEMA_MDFe + "\\evEncMDFe_v1.00.xsd", sPath);
}
catch (Exception ex)
{
throw ex;
}
objEvento = new belEventoMDFe(xmlCanc.DocumentElement, objPesquisa, "110112");
// Encerramento();
}
示例15: SaveTree
public void SaveTree(String TreeXml)
{
if (String.IsNullOrEmpty(TreeXml))
{
//创建一棵空树
XElement root = new XElement("root");
TreeXml = root.ToString();
}
using (InfocenterEntities context = new InfocenterEntities(EFConnectionString))
{
Tree treeObj = context.Trees.FirstOrDefault();
if (treeObj != null)
{
//更新树
treeObj.maintree = Encoding.UTF8.GetBytes(TreeXml);
context.SaveChanges();
}
else
{
//正常情况下应该不会走到这个分支,但仍然写在这里,逻辑就完整了。
treeObj = new Tree();
treeObj.maintree = Encoding.UTF8.GetBytes(TreeXml);
context.Trees.Add(treeObj);
context.SaveChanges();
}
}
}