本文整理汇总了C#中System.Xml.Linq.XDocument.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.ToString方法的具体用法?C# XDocument.ToString怎么用?C# XDocument.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
public XElement ProcessRequest(XElement QBXmlMsgsRq)
{
var doc = new XDocument(
new XProcessingInstruction("qbxml", string.Format("version=\"{0}\"", _qbXmlVersion)),
new XElement("QBXML",
new XElement("QBXMLMsgsRq", new XAttribute("onError", "stopOnError"),
QBXmlMsgsRq)));
if (_log.IsDebugEnabled)
_log.Debug("QBXmlMsgsRq:\n" + doc.ToString());
XElement response = null;
try
{
response = _sessionFactory.ProcessRequest(_ticket,
"<?xml version=\"1.0\"?>" + doc.ToString(SaveOptions.DisableFormatting));
}
catch (COMException e)
{
if (e.Message == "QuickBooks found an error when parsing the provided XML text stream.")
{
_log.ErrorFormat("Error parsing QBXML: \n<?xml version=\"1.0\"?>\n{0}", doc.ToString());
throw new QBException(e.Message, "", doc);
}
else
throw e;
}
return response;
}
示例2: consultaNFe
private string consultaNFe()
{
XmlSchemaCollection myschema = new XmlSchemaCollection();
string sxdoc = "";
XNamespace pf = "http://www.portalfiscal.inf.br/nfe";
try
{
XDocument xdoc = new XDocument(new XElement(pf + "consSitNFe", new XAttribute("versao", sversaoLayoutCons),//sversaoLayoutCons),
new XElement(pf + "tpAmb", Acesso.TP_AMB.ToString()),
new XElement(pf + "xServ", "CONSULTAR"),
new XElement(pf + "chNFe", objPesquisa.sCHAVENFE)));
string sCaminhoConsulta = Pastas.PROTOCOLOS + "Consulta_" + objPesquisa.sCHAVENFE + ".xml";
if (File.Exists(sCaminhoConsulta))
{
File.Delete(sCaminhoConsulta);
}
StreamWriter writer = new StreamWriter(sCaminhoConsulta);
writer.Write(xdoc.ToString());
writer.Close();
//belValidaXml.ValidarXml("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_NFE + "\\2.01\\consSitNFe_v2.01.xsd", sCaminhoConsulta);
sxdoc = xdoc.ToString();
}
catch (XmlException x)
{
throw new Exception(x.Message.ToString());
}
catch (XmlSchemaException x)
{
throw new Exception(x.Message.ToString());
}
return sxdoc;
}
示例3: GetXmlDocument
public XmlDocument GetXmlDocument()
{
XDocument document = new XDocument(this.GetXElement());
document.Declaration = new XDeclaration("1.0", "utf-8", "yes");
var xmlDoc = new XmlDocument();
var xmlAsString = document.ToString();
xmlDoc.LoadXml(document.ToString());
return xmlDoc;
}
示例4: SiteMap
public ContentResult SiteMap()
{
List<Page> pages = Page.Collection.Find(Page.ActiveScope).ToList();
List<Post> posts = Post.Collection.Find(Post.ActiveScope)
.SetSortOrder(Post.DefaultSortByScope)
.ToList();
var sitemap = new XDocument(new XDeclaration("1.0", "utf-8", "yes"),
new XElement(AppSettings.SiteMapNamespace + "urlset",
from p in pages
select
new XElement(AppSettings.SiteMapNamespace + "url",
new XElement(AppSettings.SiteMapNamespace + "loc", string.Format(AppSettings.PageUrlFormat, Request.Url.Host, p.Url)),
new XElement("lastmod", String.Format("{0:yyyy-MM-dd}", p.UpdatedOn))
),
new XElement("changefreq", "monthly"),
new XElement("priority", "0.5"),
from p in posts
select
new XElement(AppSettings.SiteMapNamespace + "url",
new XElement(AppSettings.SiteMapNamespace + "loc", string.Format(AppSettings.PostUrlFormat, Request.Url.Host, p.TitleTransliterated)),
new XElement("lastmod", String.Format("{0:yyyy-MM-dd}", p.UpdatedOn))
),
new XElement("changefreq", "monthly"),
new XElement("priority", "0.5")
)
);
return Content(sitemap.ToString(), "text/xml");
}
示例5: SiteMap
public ActionResult SiteMap()
{
var _Pages = PageService.GetSitemap(APP._SiteID, Request.Url.Authority);
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
var _Q = from i in _Pages.Pages
select
new XElement(ns + "url",
new XElement(ns + "loc", Request.Url.Scheme + "://" + Request.Url.Authority + "/" + i.FriendlyUrl)
, new XElement(ns + "changefreq", "always"));
if (_Pages.Blog)
{
_Q = _Q.Union((from i in _Pages.Posts
select
new XElement(ns + "url",
new XElement(ns + "loc", Url.Action("detail", "blog", new { BlogPostID = i.BlogPostID, FriendlyUrl = i.FriendlyUrl }, Request.Url.Scheme))
, new XElement(ns + "changefreq", "always"))))
.Union((from i in _Pages.BlogCategories
select
new XElement(ns + "url",
new XElement(ns + "loc", Url.Action("index", "blog", new { BlogCategoryFriendlyUrl = i.FriendlyUrl }, Request.Url.Scheme))
, new XElement(ns + "changefreq", "always"))))
.Union((from i in _Pages.BlogTags
select
new XElement(ns + "url",
new XElement(ns + "loc", Url.Action("tag", "blog", new { BlogTagName = i.BlogTagName }, Request.Url.Scheme))
, new XElement(ns + "changefreq", "always"))));
}
var sitemap = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new XElement(ns + "urlset", _Q));
return Content("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + sitemap.ToString(), "text/xml");
}
示例6: Save
public void Save(int tenant)
{
SetupProgress(tenant);
using (var backupWriter = new ZipWriteOperator(backup))
{
var doc = new XDocument(new XElement(ROOT, new XAttribute("tenant", tenant)));
foreach (var provider in providers.Values)
{
try
{
var elements = provider.GetElements(tenant, configs, backupWriter);
if (elements != null)
{
doc.Root.Add(new XElement(provider.Name, elements));
}
}
catch (Exception ex)
{
OnProgressError(ex);
}
}
var data = Encoding.UTF8.GetBytes(doc.ToString(SaveOptions.None));
var stream = backupWriter.BeginWriteEntry(XML_NAME);
stream.Write(data, 0, data.Length);
backupWriter.EndWriteEntry();
}
}
示例7: ToString
public override string ToString()
{
var xml = new XDocument();
var methodCall = new XElement("methodCall");
methodCall.Add(new XElement("methodName", Method));
xml.AddFirst(methodCall);
if (Parameters.Count > 0)
{
var structi = new XElement("struct");
var paramss = new XElement("params",
new XElement("param",
new XElement("value", structi)));
foreach (var xmlParameter in Parameters)
{
var member = new XElement("member", new XElement("name", xmlParameter.Name), GetParameterValue(xmlParameter.Value));
structi.Add(member);
}
methodCall.Add(paramss);
}
return xml.ToString();
}
示例8: MsSqlSelect
public static Message MsSqlSelect(this Message message, MsSqlConnectionConfig config, string selectStatement)
{
Logger.Debug("Step");
var adapter = new SqlDataAdapter(selectStatement, config.ToConnectionString());
var dataSet = new DataSet();
adapter.Fill(dataSet, "ResultTable");
var result = new XDocument(new XElement("MsSqlSelectResult"));
foreach (DataTable table in dataSet.Tables)
{
var doc = new XElement(table.TableName);
foreach (DataRow row in table.Rows)
{
var xmlRow = new XElement("Row");
foreach (DataColumn column in table.Columns)
{
xmlRow.Add(new XElement(column.ColumnName, row[column.Ordinal].ToString()));
}
doc.Add(xmlRow);
}
result.Root.Add(doc);
}
message.SetPayload(result.ToString());
return message;
}
示例9: GetSiteMapXml
public void GetSiteMapXml(Uri uri, string path, ISet<string> urls)
{
IndexedPagesCount = urls.Count;
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
var sitemap = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "urlset",
from i in urls
select
//Add ns to every element.
new XElement(ns + "url",
new XElement(ns + "loc", i)
)
)
);
string headerXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n";
Byte[] info = new UTF8Encoding(true).GetBytes(headerXml + sitemap.ToString());
using (FileStream fs = File.Create(path + uri.Authority + ".xml"))
{
// Add some information to the file.
fs.Write(info, 0, info.Length);
}
}
示例10: DisassembleXmlFromEndpointTest
public void DisassembleXmlFromEndpointTest()
{
// Goal: Send in bytes (from stream) and get an XML document out
var disassembler = new XmlDisassembler();
XDocument document = new XDocument(new XElement("body",
new XElement("level1",
new XElement("level2", "text"),
new XElement("level2", "other text"))));
document.Declaration = new XDeclaration("1.0", "UTF-8", "yes");
byte[] data = Encoding.GetEncoding(document.Declaration.Encoding).GetBytes(document.ToString());
disassembler.Disassemble(data);
Message message = disassembler.NextMessage();
Assert.IsNull(disassembler.NextMessage(), "Expected only one message back");
Assert.IsNotNull(message);
Assert.IsNotNull(message.Stream);
Assert.IsTrue(XNode.DeepEquals(document, XDocument.Parse(message.GetString())));
Assert.IsTrue(XNode.DeepEquals(document, XDocument.Load(message.GetStream())));
// Move these to MessageTest instead
Assert.IsTrue(XNode.DeepEquals(document, message.RetrieveAs<XDocument>()));
Assert.IsTrue(XNode.DeepEquals(document, message.RetrieveAs<XNode>()));
Assert.IsTrue(XNode.DeepEquals(document, XDocument.Parse(message.RetrieveAs<XmlDocument>().OuterXml)));
}
示例11: GenerateXml
/// <summary>
/// The generate xml.
/// </summary>
/// <param name="page">
/// The page.
/// </param>
/// <returns>
/// The <see cref="string"/>.
/// </returns>
public static string GenerateXml(IContent page)
{
if (page == null)
{
return string.Empty;
}
XDocument xDocument = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), new object[0]);
XElement xElement = new XElement("content");
xElement.SetAttributeValue("name", XmlConvert.EncodeName(page.Name));
List<KeyValuePair<string, string>> propertyValues = page.GetPropertyValues();
foreach (KeyValuePair<string, string> content in propertyValues)
{
XElement xElement3 = new XElement(XmlConvert.EncodeName(content.Key));
xElement3.SetValue(TextIndexer.StripHtml(content.Value, content.Value.Length));
xElement.Add(xElement3);
}
xDocument.Add(xElement);
return xDocument.ToString();
}
示例12: writeScore
/**
* Speichert den Score
*/
public void writeScore(ErrorCallback ecb, string playerName, int score, int level, long time, int mode)
{
time /= 10000;
this.ecb = ecb;
XDocument doc = new XDocument(
new XElement("scoreentry",
new XElement("playername", playerName),
new XElement("score", score),
new XElement("level", level),
new XElement("time", time),
new XElement("mode", mode)
)
);
postData = doc.ToString();
try
{
WebRequest request = WebRequest.Create(proxy);
request.Method = "POST";
request.ContentType = "text/xml";
request.BeginGetRequestStream(new AsyncCallback(RequestReady), request);
}
catch (Exception e)
{ ecb(e.Message); }
}
示例13: ApplyFragment
/// <summary>
/// Updates the underlying store with this as the new representation of the identified resource
/// </summary>
/// <param name="resourceUri">The resource for whom this is the representation</param>
/// <param name="resourceDescription">The rdf xml document that describes the resource</param>
public override void ApplyFragment(string resourceUri, XDocument resourceDescription)
{
try
{
var wr = WebRequest.Create(_endpoint + "?" + _resourceParameterName + "=" + resourceUri);
wr.Method = "POST";
wr.ContentType = "application/rdf+xml";
var reqstream = wr.GetRequestStream();
using (var strwriter = new StreamWriter(reqstream))
{
strwriter.WriteLine(resourceDescription.ToString());
}
// get response
var resp = wr.GetResponse() as HttpWebResponse;
if (resp.StatusCode != HttpStatusCode.OK || resp.StatusCode != HttpStatusCode.Accepted)
{
Logging.LogError(1, "Error in apply fragment. Remote server returned code {0}", resp.StatusCode);
}
resp.Close();
} catch(Exception ex)
{
Logging.LogError(1, "Error in apply fragment {0}", ex.Message);
}
}
示例14: Index
public ContentResult Index()
{
//Scraping SO feed
var url = "http://stackoverflow.com/feeds";
XmlReader reader = XmlReader.Create(url);
SyndicationFeed feed = SyndicationFeed.Load(reader);
var q = from item in feed.Items
select new {
Title = item.Title,
URL = item.Id,
Date = item.PublishDate
};
//Build the SiteMap
XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9";
var sitemap = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement(ns + "urlset",
from i in q
select
new XElement(ns + "url",
new XElement(ns + "loc", i.URL),
new XElement(ns + "lastmod", String.Format("{0:yyyy-MM-dd}", i.Date)),
new XElement(ns + "changefreq", "monthly"),
new XElement(ns + "priority", "0.5")
)
)
);
return Content(sitemap.ToString(), "text/xml");
}
示例15: Main
static void Main(string[] args)
{
//根目录
string rootPath = @"E:\";
var dir = new DirectoryInfo(rootPath);
//递归获得目录树
var doc = new XDocument(GetDirectoryXml(dir));
//将目录树存入文件haha.txt
System.IO.File.WriteAllText("haha.txt", doc.ToString());
//读入目录树文件
XDocument xdoc = XDocument.Load("haha.txt");
//获得文件中第一级的所有XElements,也就是我们的根目录E
List<XElement> els = xdoc.Elements().ToList<XElement>();
//获得文件中第一级第一个Element的子Elements(也就是第二级)
List<XElement> es = els[0].Elements().ToList<XElement>();
for (int i = 0; i < es.Count; i++)
{//遍历第二级
XElement currElement = es[i];
//按照文件结构的设计,每一个element都只有一个attribute
XAttribute currElementsAttribute = currElement.FirstAttribute;
//name也就是当前element的名字,或者是dir,或者是file,如果是dir那就可以继续展开这个element,得到他的子elements
string name = currElement.Name.ToString();
//当前element的attribute的value存了文件名或文件夹名
string path = currElementsAttribute.Value.ToString();
Console.WriteLine(name + ":" + path);
}
Console.ReadLine();
}