当前位置: 首页>>代码示例>>C#>>正文


C# XDocument.ToStringWithDeclaration方法代码示例

本文整理汇总了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();
        }
开发者ID:skazantsev,项目名称:WebDavClient,代码行数:12,代码来源:LockRequestBuilder.cs

示例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();
        }
开发者ID:bencz,项目名称:OrangeC,代码行数:54,代码来源:HelpIndexManager.cs

示例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();
 }
开发者ID:skazantsev,项目名称:WebDavClient,代码行数:22,代码来源:PropfindRequestBuilder.cs

示例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();
        }
开发者ID:skazantsev,项目名称:WebDavClient,代码行数:38,代码来源:ProppatchRequestBuilder.cs

示例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;
		}
开发者ID:iamhenning,项目名称:UPnPLite,代码行数:25,代码来源:UPnPService.cs

示例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");
        }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:35,代码来源:StoneEdgeController.cs

示例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();
        }
开发者ID:bencz,项目名称:OrangeC,代码行数:68,代码来源:HelpIndexManager.cs

示例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();
        }
开发者ID:bencz,项目名称:OrangeC,代码行数:38,代码来源:HelpIndexManager.cs

示例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();
        }
开发者ID:clonly,项目名称:vshdp,代码行数:56,代码来源:HelpIndexManager.cs

示例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();
        }
开发者ID:clonly,项目名称:vshdp,代码行数:101,代码来源:HelpIndexManager.cs


注:本文中的System.Xml.Linq.XDocument.ToStringWithDeclaration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。