本文整理汇总了C#中System.Xml.Linq.XDocument.ToStringWithDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.ToStringWithDeclaration方法的具体用法?C# XDocument.ToStringWithDeclaration怎么用?C# XDocument.ToStringWithDeclaration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.ToStringWithDeclaration方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BuildRequestBody
public static string BuildRequestBody(LockParameters lockParams)
{
var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));
var lockinfo = new XElement("{DAV:}lockinfo", new XAttribute(XNamespace.Xmlns + "D", "DAV:"));
lockinfo.Add(GetLockScope(lockParams.LockScope));
lockinfo.Add(GetLockType());
if (lockParams.Owner != null)
lockinfo.Add(GetLockOwner(lockParams.Owner));
doc.Add(lockinfo);
return doc.ToStringWithDeclaration();
}
示例2: CreateBookGroupBooksIndex
/// <summary>
/// Create book group books index.
/// </summary>
/// <param name="bookGroup">
/// The book group to create the index for.
/// </param>
/// <returns>
/// The xml document text
/// </returns>
public static string CreateBookGroupBooksIndex( BookGroup bookGroup )
{
XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );
XElement headElement = CreateElement( "head", null, null );
XElement metaDateElemet = CreateElement( "meta", null, null );
metaDateElemet.SetAttributeValue( XName.Get( "http-equiv", string.Empty ), "Date" );
metaDateElemet.SetAttributeValue( XName.Get( "content", string.Empty ), DateTime.Now.ToString( "R", CultureInfo.InvariantCulture ) );
headElement.Add( metaDateElemet );
XElement bodyElement = CreateElement( "body", "product", null );
XElement detailsElement = CreateElement( "div", "details", null );
detailsElement.Add(
CreateElement( "span", "name", bookGroup.Name ),
CreateElement( "span", "locale", bookGroup.Locale.Code ),
CreateElement( "span", "description", bookGroup.Description ) );
XElement bookListElement = CreateElement( "div", "book-list", null );
foreach ( Book book in bookGroup.Books )
{
if ( book.Wanted )
{
XElement bookElement = CreateElement( "div", "book", null );
XElement linkElement = CreateElement( "a", "book-link", null );
linkElement.SetAttributeValue( XName.Get( "href", string.Empty ), book.CreateFileName() );
bookElement.Add(
CreateElement( "span", "name", book.Name ),
CreateElement( "span", "locale", book.Locale.Code ),
CreateElement( "span", "description", book.Description ),
linkElement );
bookListElement.Add( bookElement );
}
}
bodyElement.Add( detailsElement, bookListElement );
if ( document.Root != null )
{
document.Root.Add( headElement, bodyElement );
}
return document.ToStringWithDeclaration();
}
示例3: BuildRequestBody
public static string BuildRequestBody(IReadOnlyCollection<XName> customProperties, IReadOnlyCollection<NamespaceAttr> namespaces)
{
var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));
var propfind = new XElement("{DAV:}propfind", new XAttribute(XNamespace.Xmlns + "D", "DAV:"));
propfind.Add(new XElement("{DAV:}allprop"));
if (customProperties.Any())
{
var include = new XElement("{DAV:}include");
foreach (var ns in namespaces)
{
var nsAttr = string.IsNullOrEmpty(ns.Prefix) ? "xmlns" : XNamespace.Xmlns + ns.Prefix;
include.SetAttributeValue(nsAttr, ns.Namespace);
}
foreach (var prop in customProperties)
{
include.Add(new XElement(prop));
}
propfind.Add(include);
}
doc.Add(propfind);
return doc.ToStringWithDeclaration();
}
示例4: BuildRequestBody
public static string BuildRequestBody(IDictionary<XName, string> propertiesToSet,
IReadOnlyCollection<XName> propertiesToRemove,
IReadOnlyCollection<NamespaceAttr> namespaces)
{
var doc = new XDocument(new XDeclaration("1.0", "utf-8", null));
var propertyupdate = new XElement("{DAV:}propertyupdate", new XAttribute(XNamespace.Xmlns + "D", "DAV:"));
foreach (var ns in namespaces)
{
var nsAttr = string.IsNullOrEmpty(ns.Prefix) ? "xmlns" : XNamespace.Xmlns + ns.Prefix;
propertyupdate.SetAttributeValue(nsAttr, ns.Namespace);
}
if (propertiesToSet.Any())
{
var setEl = new XElement("{DAV:}set");
foreach (var prop in propertiesToSet)
{
var el = new XElement(prop.Key);
el.SetInnerXml(prop.Value);
setEl.Add(new XElement(XName.Get("prop", "DAV:"), el));
}
propertyupdate.Add(setEl);
}
if (propertiesToRemove.Any())
{
var removeEl = new XElement("{DAV:}remove");
foreach (var prop in propertiesToRemove)
{
removeEl.Add(
new XElement(XName.Get("prop", "DAV:"),
new XElement(prop)));
}
propertyupdate.Add(removeEl);
}
doc.Add(propertyupdate);
return doc.ToStringWithDeclaration();
}
示例5: CreateActionRequest
private string CreateActionRequest(string action, Dictionary<string, object> parameters)
{
var u = XNamespace.Get(this.ServiceType);
var encodingStyle = XNamespace.Get("http://schemas.xmlsoap.org/soap/encoding/");
var actionElement = new XElement(u + action, new XAttribute(XNamespace.Xmlns + "u", u.NamespaceName));
if (parameters != null && parameters.Any())
{
foreach (var parameter in parameters)
{
actionElement.Add(new XElement(parameter.Key, parameter.Value));
}
}
var envelope = new XDocument(
new XDeclaration("1.0", "utf-8", null),
new XElement(Namespaces.Envelope + "Envelope",
new XAttribute(XNamespace.Xmlns + "s", Namespaces.Envelope.NamespaceName),
new XAttribute(Namespaces.Envelope + "encodingStyle", encodingStyle.NamespaceName),
new XElement(Namespaces.Envelope + "Body", actionElement)));
var stEnvelope = envelope.ToStringWithDeclaration();
return stEnvelope;
}
示例6: RenderErrors
private ActionResult RenderErrors()
{
if (_Errors.Count < 1) return Content("SETIError: No Error Message To Render", "text/plain");
var err = _Errors[0];
// Dump Generic Errors
string errorTag = "SETI";
switch (err.ErrorType)
{
case StoneEdgeErrorType.Customers:
errorTag += "Customers";
break;
case StoneEdgeErrorType.Orders:
errorTag += "Orders";
break;
case StoneEdgeErrorType.Products:
errorTag += "Products";
break;
default:
return Content("SETIError: " + err.Message, "text/plain");
}
XDocument xdoc =
new XDocument(
new XElement(errorTag,
new XElement("Response",
new XElement("ResponseCode", "3"),
new XElement("ResponseDescription", err.Message)
)
)
);
return Content(xdoc.ToStringWithDeclaration(), "application/xml");
}
示例7: CreateBookPackagesIndex
/// <summary>
/// Create book packages index.
/// </summary>
/// <param name="bookGroup">
/// The book Group associated with the book.
/// </param>
/// <param name="book">
/// The book associated with the packages
/// </param>
/// <returns>
/// The xml document text
/// </returns>
public static string CreateBookPackagesIndex( BookGroup bookGroup, Book book )
{
XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );
XElement headElement = CreateElement( "head", null, null );
XElement metaDateElemet = CreateElement( "meta", null, null );
metaDateElemet.SetAttributeValue( XName.Get( "http-equiv", string.Empty ), "Date" );
metaDateElemet.SetAttributeValue( XName.Get( "content", string.Empty ), DateTime.Now.ToString( "R", CultureInfo.InvariantCulture ) );
headElement.Add( metaDateElemet );
XElement bodyElement = CreateElement( "body", "book", null );
XElement detailsElement = CreateElement( "div", "details", null );
XElement brandingPackageElement1 = CreateElement( "a", "branding-package-link", null );
XElement brandingPackageElement2 = CreateElement( "a", "branding-package-link", null );
XElement productLinkElement = CreateElement( "a", "product-link", null );
productLinkElement.SetAttributeValue( XName.Get( "href", string.Empty ), bookGroup.CreateFileName() );
detailsElement.Add(
CreateElement( "span", "name", book.Name ),
CreateElement( "span", "description", book.Description ),
CreateElement( "span", "vendor", "Microsoft" ),
CreateElement( "span", "locale", book.Locale.Code ),
brandingPackageElement1,
brandingPackageElement2 );
XElement packageListElement = CreateElement( "div", "package-list", null );
foreach ( Package package in book.Packages )
{
XElement packageElement = CreateElement( "div", "package", null );
XElement linkElement = CreateElement( "a", "current-link", null );
linkElement.SetAttributeValue(
XName.Get( "href", string.Empty ),
string.Format( CultureInfo.InvariantCulture, @"Packages\{0}", package.CreateFileName() ) );
packageElement.Add(
CreateElement( "span", "name", package.Name ),
CreateElement( "span", "deployed", "true" ),
CreateElement( "span", "package-etag", package.Tag ),
CreateElement( "span", "last-modified", package.LastModified.ToUniversalTime().ToString( "O", CultureInfo.InvariantCulture ) ),
linkElement );
packageListElement.Add( packageElement );
}
bodyElement.Add( detailsElement, packageListElement );
if ( document.Root != null )
{
document.Root.Add( headElement, bodyElement );
}
return document.ToStringWithDeclaration();
}
示例8: CreateSetupIndex
/// <summary>
/// Creates main help setup index.
/// </summary>
/// <param name="bookGroups">
/// A collection of book groups to add to the index
/// </param>
/// <returns>
/// The xml document text
/// </returns>
public static string CreateSetupIndex( IEnumerable<BookGroup> bookGroups )
{
XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );
XElement bodyElement = CreateElement( "body", "product-list", null );
foreach ( BookGroup bookGroup in bookGroups )
{
XElement productElement = CreateElement( "div", "product", null );
XElement linkElement = CreateElement( "a", "product-link", null );
linkElement.SetAttributeValue( XName.Get( "href", string.Empty ), bookGroup.CreateFileName() );
productElement.Add(
CreateElement( "span", "name", bookGroup.Name ),
CreateElement( "span", "locale", bookGroup.Locale.Code ),
CreateElement( "span", "description", bookGroup.Description ),
linkElement );
bodyElement.Add( productElement );
}
if ( document.Root != null )
{
document.Root.Add( bodyElement );
}
return document.ToStringWithDeclaration();
}
示例9: CreateSetupIndex
/// <summary>
/// Creates main help setup index.
/// </summary>
/// <param name="bookGroups">
/// A collection of book groups to add to the index
/// </param>
/// <returns>
/// The xml document text
/// </returns>
public static string CreateSetupIndex( IEnumerable<BookGroup> bookGroups, string nameCatalog, string codeLocale )
{
XDocument document = new XDocument( new XDeclaration( "1.0", "utf-8", null ), CreateElement( "html", null, null ) );
XElement headElement = CreateElement( "head", null, null );
XElement metaDateElemet1 = CreateElement( "meta", null, null );
metaDateElemet1.SetAttributeValue( XName.Get( "name", string.Empty ), "ROBOTS" );
metaDateElemet1.SetAttributeValue( XName.Get( "content", string.Empty ), "NOINDEX, NOFOLLOW" );
XElement metaDateElemet2 = CreateElement( "meta", null, null );
metaDateElemet2.SetAttributeValue( XName.Get( "http-equiv", string.Empty ), "Content-Location" );
metaDateElemet2.SetAttributeValue(
XName.Get( "content", string.Empty ),
string.Format( CultureInfo.InvariantCulture, @"http://services.mtps.microsoft.com/serviceapi/catalogs/{0}/{1}",
nameCatalog.ToLowerInvariant( ), codeLocale));
XElement linkElement = CreateElement( "link", null, null );
linkElement.SetAttributeValue( XName.Get( "type", string.Empty ), "text/css" );
linkElement.SetAttributeValue( XName.Get( "rel", string.Empty ), "stylesheet" );
linkElement.SetAttributeValue( XName.Get( "href", string.Empty), "../../styles/global.css" );
XElement titleElement = CreateElement( "title", null, "All Book Listings" );
headElement.Add( metaDateElemet1 );
headElement.Add( metaDateElemet2 );
headElement.Add( linkElement );
headElement.Add( titleElement );
XElement bodyElement = CreateElement( "body", "book-list", null );
XElement detailsElement = CreateElement( "div", "details", null );
XElement catalogLocaleLinkElement = CreateElement( "a", "catalog-locale-link", "Catalog locales" );
catalogLocaleLinkElement.SetAttributeValue( XName.Get( "href", string.Empty ),
string.Format(CultureInfo.InvariantCulture, @"../../catalogs/{0}", nameCatalog.ToLowerInvariant()));
detailsElement.Add( catalogLocaleLinkElement );
XElement bookgroupsElement = CreateBookGroupBooksIndex ( bookGroups, codeLocale );
bodyElement.Add(detailsElement, bookgroupsElement);
if ( document.Root != null )
{
document.Root.Add( headElement, bodyElement );
}
return document.ToStringWithDeclaration();
}
示例10: CreateBookPackagesIndex
//.........这里部分代码省略.........
foreach (MSDNPath path in book.Paths)
{
XElement pathElement = CreateElement("div", "path", null);
pathElement.Add(
CreateElement( "span", "languages", path.Languages ),
CreateElement( "span", "membership", path.Membership ),
CreateElement( "span", "name", path.Name ),
CreateElement( "span", "priority", path.Priority.ToString() ),
CreateElement( "span", "skuId", path.SkuId.ToString() ),
CreateElement( "span", "skuName", path.SkuName )
);
pathsElement.Add( pathElement );
}
propertiesElement.Add( pathsElement );
XElement packageListElement = CreateElement( "div", "packages", null );
string packageListTick = @"The following packages are available: in this book:";
//packageListElement.Add( new XText( packageListTick ) );
//packageListElement.Value = packageListTick;
XElement child1 = packageListElement.Element( "div" );
//child1.( packageListTick );
//child1.AddAfterSelf( new XElement( packageListTick ) );
string deployedTick = @"Deployed: ";
string leftRoundBracketsTick = @"(Package Constituents: ";
string rightRoundBracketsTick = @")";
foreach ( Package package in book.Packages )
{
XElement packageElement = CreateElement( "div", "package", null );
XElement currentLinkElement = CreateElement( "a", "current-link", package.CreateFileName() );
string curlink = string.Format( CultureInfo.InvariantCulture, "packages/{0}", ( package.CreateFileName() ).ToLowerInvariant() );
if ( package.Name.ToLowerInvariant().Contains( @"en-us" ) )
curlink = string.Format( CultureInfo.InvariantCulture, "packages/en-us/{0}", ( package.CreateFileName() ).ToLowerInvariant() );
else if ( package.Name.ToLowerInvariant().Contains( codeLocale.ToLowerInvariant() ) )
curlink = string.Format( CultureInfo.InvariantCulture, "packages/{0}/{1}", codeLocale.ToLowerInvariant() , ( package.CreateFileName() ).ToLowerInvariant());
else
curlink = string.Format( CultureInfo.InvariantCulture, "packages/{0}", ( package.CreateFileName() ).ToLowerInvariant() );
currentLinkElement.SetAttributeValue(
XName.Get( "href", string.Empty ),
curlink
);
XElement constituentLinkElement = CreateElement("a", "package-constituent-link", package.Name);
constituentLinkElement.SetAttributeValue( XName.Get( "href", string.Empty), package.ConstituentLink );
XElement lastModified;
if ( ( package.LastModified.Millisecond % 10 ) == 0 )
lastModified = CreateElement( "span", "last-modified", package.LastModified.ToUniversalTime().ToString( "yyyy-MM-ddThh:mm:ss.ffZ", CultureInfo.InvariantCulture ) );
else
lastModified = CreateElement( "span", "last-modified", package.LastModified.ToUniversalTime().ToString( "yyyy-MM-ddThh:mm:ss.fffZ", CultureInfo.InvariantCulture ) );
packageElement.Add(
CreateElement( "span", "packageType", package.PackageType ),
CreateElement( "span", "packageFormat", package.PackageFormat),
CreateElement( "span", "name", package.Name ),
//new XText( @"Deployed: " ),
CreateElement( "span", "deployed", package.Deployed ),
lastModified,
CreateElement( "span", "package-etag", package.Tag ),
currentLinkElement,
CreateElement( "span", "package-size-bytes", package.Size.ToString() ),
CreateElement( "span", "package-size-bytes-uncompressed", package.UncompressedSize.ToString() ),
//new XText( @"(Package Constituents: " ),
constituentLinkElement
//new XText( @")" )
);
packageListElement.Add( packageElement );
}
bookElement.Add(
CreateElement( "span", "id", book.Code ),
CreateElement( "span", "locale", book.Locale.Code ),
CreateElement( "span", "name", book.Name ),
CreateElement( "span", "description", book.Description ),
CreateElement( "span", "BrandingPackageName", book.BrandingPackageName ),
propertiesElement,
packageListElement
);
bookgroupElement.Add(bookElement);
}
bookgroupsElement.Add(bookgroupElement);
}
bodyElement.Add(detailsElement, bookgroupsElement);
if ( document.Root != null )
{
document.Root.Add( headElement, bodyElement );
}
return document.ToStringWithDeclaration();
}