當前位置: 首頁>>代碼示例>>C#>>正文


C# XmlDocument.Beautify方法代碼示例

本文整理匯總了C#中System.Xml.XmlDocument.Beautify方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.Beautify方法的具體用法?C# XmlDocument.Beautify怎麽用?C# XmlDocument.Beautify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Xml.XmlDocument的用法示例。


在下文中一共展示了XmlDocument.Beautify方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: BeautifyXml

 static public string BeautifyXml(this string xml)
 {
     var doc = new XmlDocument();
     doc.LoadXml(xml);
     return doc.Beautify();
 }
開發者ID:OfficeDev,項目名稱:Office-IT-Pro-Deployment-Scripts,代碼行數:6,代碼來源:Extensions.cs

示例2: CreateLogMessage

 private static string CreateLogMessage(IHttpListenerContext context, string callInfo, XmlDocument request, XmlDocument response, StringBuilder requestHeader, String xLitmusTest)
 {
     var message = String.Format("{5}WEB-DAV-CALL-ENDED: {0}\r\nREQUEST HEADER\r\n{1}\r\nRESPONSE HEADER\r\n{2}\r\nrequest:{3}\r\nresponse{4}",
         callInfo,
         requestHeader,
         context.Response.DumpHeaders(),
         request.Beautify(),
         response.Beautify(),
         xLitmusTest);
     return message;
 }
開發者ID:ProximoSrl,項目名稱:WebDAVSharp.Server,代碼行數:11,代碼來源:WebDAVServer.cs

示例3: OnProcessRequest


//.........這裏部分代碼省略.........
                        request.DocumentElement.LocalName != "lockinfo")
                    {
                        WebDavServer.Log.Debug("LOCK method without prop or lockinfo element in xml document");
                    }

                    manager = new XmlNamespaceManager(request.NameTable);
                    manager.AddNamespace("D", "DAV:");
                    manager.AddNamespace("Office", "schemas-microsoft-com:office:office");
                    manager.AddNamespace("Repl", "http://schemas.microsoft.com/repl/");
                    manager.AddNamespace("Z", "urn:schemas-microsoft-com:");

                    // Get the lockscope, locktype and owner as XmlNodes from the XML document
                    lockscopeNode = request.DocumentElement.SelectSingleNode("D:lockscope", manager);
                    locktypeNode = request.DocumentElement.SelectSingleNode("D:locktype", manager);
                    ownerNode = request.DocumentElement.SelectSingleNode("D:owner", manager);
                }
                catch (Exception ex)
                {
                    WebDavServer.Log.Warn(ex.Message);
                    throw;
                }

                #endregion
            }

            /***************************************************************************************************
             * Create the body for the response
             ***************************************************************************************************/

            // Create the basic response XmlDocument
            const string responseXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><D:prop xmlns:D=\"DAV:\"><D:lockdiscovery><D:activelock/></D:lockdiscovery></D:prop>";
            response.LoadXml(responseXml);

            // Select the activelock XmlNode
            XmlNode activelock = response.DocumentElement.SelectSingleNode("D:lockdiscovery/D:activelock", manager);

            // Import the given nodes
            activelock.AppendChild(response.ImportNode(lockscopeNode, true));
            activelock.AppendChild(response.ImportNode(locktypeNode, true));
            activelock.AppendChild(response.ImportNode(ownerNode, true));

            // Add the additional elements, e.g. the header elements

            // The timeout element
            WebDavProperty timeoutProperty = new WebDavProperty("timeout", timeout);// timeout);
            activelock.AppendChild(timeoutProperty.ToXmlElement(response));

            // The depth element
            WebDavProperty depthProperty = new WebDavProperty("depth", (depth == 0 ? "0" : "Infinity"));
            activelock.AppendChild(depthProperty.ToXmlElement(response));

            // The locktoken element
            WebDavProperty locktokenProperty = new WebDavProperty("locktoken", string.Empty);
            XmlElement locktokenElement = locktokenProperty.ToXmlElement(response);
            WebDavProperty hrefProperty = new WebDavProperty("href", locktoken);//"opaquelocktoken:e71d4fae-5dec-22df-fea5-00a0c93bd5eb1");
            locktokenElement.AppendChild(hrefProperty.ToXmlElement(response));
            activelock.AppendChild(locktokenElement);

            // The lockroot element
            WebDavProperty lockRootProperty = new WebDavProperty("lockroot", string.Empty);
            XmlElement lockRootElement = lockRootProperty.ToXmlElement(response);
            WebDavProperty hrefRootProperty = new WebDavProperty("href", context.Request.Url.AbsoluteUri);//"lockroot
            lockRootElement.AppendChild(hrefRootProperty.ToXmlElement(response));
            activelock.AppendChild(lockRootElement);

            /***************************************************************************************************
             * Send the response
             ***************************************************************************************************/

            // convert the StringBuilder
            string resp = response.InnerXml;
            if (WebDavServer.Log.IsDebugEnabled)
            {
                WebDavServer.Log.DebugFormat(
@"Request {0}:{1}:{2}
Request
{3}
Response:
{4}",
                context.Request.HttpMethod, context.Request.RemoteEndPoint, context.Request.Url,
                request.Beautify(),
                response.Beautify());
            }


            byte[] responseBytes = Encoding.UTF8.GetBytes(resp);


            context.Response.StatusCode = lockResult;
            context.Response.StatusDescription = HttpWorkerRequest.GetStatusDescription(lockResult);

            // set the headers of the response
            context.Response.ContentLength64 = responseBytes.Length;
            context.Response.AdaptedInstance.ContentType = "text/xml";

            // the body
            context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length);

            context.Response.Close();
        }
開發者ID:ProximoSrl,項目名稱:WebDAVSharp.Server,代碼行數:101,代碼來源:WebDAVLockMethodHandler.cs

示例4: OnProcessRequest

        /// <summary>
        /// Processes the request.
        /// </summary>
        /// <param name="server">The <see cref="WebDavServer" /> through which the request came in from the client.</param>
        /// <param name="context">The
        /// <see cref="IHttpListenerContext" /> object containing both the request and response
        /// objects to use.</param>
        /// <param name="store">The <see cref="IWebDavStore" /> that the <see cref="WebDavServer" /> is hosting.</param>
        /// <exception cref="WebDAVSharp.Server.Exceptions.WebDavUnauthorizedException"></exception>
        /// <param name="response"></param>
        /// <param name="request"></param>
        protected override void OnProcessRequest(
           WebDavServer server,
           IHttpListenerContext context,
           IWebDavStore store,
           XmlDocument request,
           XmlDocument response)
        {
            _Context = context;
            /***************************************************************************************************
             * Retreive all the information from the request
             ***************************************************************************************************/

            // Read the headers, ...
            bool isPropname = false;
            int depth = GetDepthHeader(context.Request);
            _requestUri = GetRequestUri(context.Request.Url.ToString());
            try
            {
                var webDavStoreItem = context.Request.Url.GetItem(server, store);
                _webDavStoreItems = GetWebDavStoreItems(webDavStoreItem, depth);
            }
            catch (UnauthorizedAccessException)
            {
                throw new WebDavUnauthorizedException();
            }

            // Get the XmlDocument from the request
            var requestDocument = GetXmlDocument(context.Request);

            // See what is requested
            _requestedProperties = new List<WebDavProperty>();
            if (requestDocument != null && requestDocument.DocumentElement != null)
            {
                if (requestDocument.DocumentElement.LocalName != "propfind")
                    WebDavServer.Log.Debug("PROPFIND method without propfind in xml document");
                else
                {
                    XmlNode n = requestDocument.DocumentElement.FirstChild;
                    if (n == null)
                        WebDavServer.Log.Debug("propfind element without children");
                    else
                    {
                        switch (n.LocalName)
                        {
                            case "allprop":
                                _requestedProperties = GetAllProperties();
                                break;
                            case "propname":
                                isPropname = true;
                                _requestedProperties = GetAllProperties();
                                break;
                            case "prop":
                                foreach (XmlNode child in n.ChildNodes)
                                    _requestedProperties.Add(new WebDavProperty(child.LocalName, "", child.NamespaceURI));
                                break;
                            default:
                                _requestedProperties.Add(new WebDavProperty(n.LocalName, "", n.NamespaceURI));
                                break;
                        }
                    }
                }
            }
            else
                _requestedProperties = GetAllProperties();

            /***************************************************************************************************
             * Create the body for the response
             ***************************************************************************************************/
            XmlDocument responseDoc = ResponseDocument(context, isPropname, response);

            /***************************************************************************************************
             * Send the response
             ***************************************************************************************************/
            if (WebDavServer.Log.IsDebugEnabled)
            {
                WebDavServer.Log.DebugFormat(
@"Request {0}:{1}:{2}
Request
{3}
Response:
{4}",
                context.Request.HttpMethod, context.Request.RemoteEndPoint, context.Request.Url,
                request.Beautify(), 
                response.Beautify());
            }


            SendResponse(context, response);
        }
開發者ID:ProximoSrl,項目名稱:WebDAVSharp.Server,代碼行數:100,代碼來源:WebDAVPropfindMethodHandler.cs


注:本文中的System.Xml.XmlDocument.Beautify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。