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


C# XDoc.HasName方法代码示例

本文整理汇总了C#中XDoc.HasName方法的典型用法代码示例。如果您正苦于以下问题:C# XDoc.HasName方法的具体用法?C# XDoc.HasName怎么用?C# XDoc.HasName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XDoc的用法示例。


在下文中一共展示了XDoc.HasName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Convert

 //--- Methods ---
 public string Convert(XDoc html)
 {
     if(html == null || html.IsEmpty) {
         return "";
     }
     var state = new VisitState();
     var body = html.HasName("body") ? html : html["body[not(@target)]"];
     foreach(var node in body.VisitOnly(x => IncludeNode(x, state), x => CheckBlock(x, state))) {
         if(CheckBlock(node, state)) {
             continue;
         }
         switch(node.AsXmlNode.NodeType) {
         case XmlNodeType.Whitespace:
         case XmlNodeType.SignificantWhitespace:
         case XmlNodeType.CDATA:
         case XmlNodeType.Text:
             state.Append(node.AsText);
             break;
         }
     }
     return state.ToString().Trim();
 }
开发者ID:bjorg,项目名称:DReAM,代码行数:23,代码来源:Html2Text.cs

示例2: ProcessGroupMemberInput

        private static UserBE[] ProcessGroupMemberInput(GroupBE group, XDoc userList) {
            if(!userList.HasName("users")) {
                throw new GroupExpectedUserRootNodeInvalidArgumentException();
            }

            ServiceBE service = ServiceBL.GetServiceById(group.ServiceId);
            if(service == null) {
                throw new GroupServiceNotFoundFatalException(group.ServiceId, group.Name);
            }

            //Changing members of an external group is not supported. You may modify members in the external provider instead.
            if(!ServiceBL.IsLocalAuthService(service)) {
                throw new ExternalGroupMemberInvalidOperationException();
            }

            UserBE[] members = ReadUserListXml(userList);
            ValidateGroupMemberList(service, members);
            return members;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:19,代码来源:GroupBL.cs

示例3: ReadGrantsXml

        public static List<GrantBE> ReadGrantsXml(XDoc grantsXml, PageBE page, bool ignoreInvalid) {

            List<GrantBE> grants = new List<GrantBE>();
            GrantBE g = null;

            if(!grantsXml.IsEmpty) {
                if(grantsXml.HasName("grant")) {
                    try {
                        g = ReadGrantXml(grantsXml, page);
                    } catch(ArgumentException x) {
                        if(!ignoreInvalid) {
                            throw new PermissionsGrantParseInvalidArgumentException(x.Message);
                        }
                    }
                    if(g != null) {
                        grants.Add(g);
                    }
                }
                    //If rootnode is grants, pawn off inner xml to GrantFromXml in a loop.
                else if(grantsXml.HasName("grants") || grantsXml.HasName("grants.added") || grantsXml.HasName("grants.removed")) {
                    foreach(XDoc grantXml in grantsXml["grant"]) {
                        try {
                            g = ReadGrantXml(grantXml, page);
                        } catch(ArgumentException x) {
                            if(!ignoreInvalid) {
                                throw new PermissionsGrantParseInvalidArgumentException(x.Message);
                            }
                        }
                        if(g != null) {
                            grants.Add(g);
                        }
                    }
                }
            }
            return grants;
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:36,代码来源:PermissionsBL.cs

示例4: RunScript

        public void RunScript(XDoc script, string path) {

            // check if a filename was provided
            string filename = script["@src"].AsText;
            if(filename != null) {

                // check if filename is relative
                if(!Path.IsPathRooted(filename) && (path != null)) {
                    filename = Path.Combine(path, filename);
                }

                // attempt to load script file
                if(!File.Exists(filename)) {
                    throw new FileNotFoundException(string.Format("script not found: {0}", filename));
                }
                script = XDocFactory.LoadFrom(filename, MimeType.XML);
            }

            // execute script
            if(script == null) {
                throw new Exception(string.Format("invalid script: {0}", script.AsText));
            }

            // convert <config> element into a <script> element
            if(script.HasName("config")) {
                XDoc doc = new XDoc("script");
                doc.Start("action").Attr("verb", "POST").Attr("path", "/host/services");
                doc.Add(script);
                doc.End();
                script = doc;
            }

            // execute script
            _host.At("execute").Post(script);
        }
开发者ID:nataren,项目名称:DReAM,代码行数:35,代码来源:DreamHost.cs

示例5: AddXDoc

        private void AddXDoc(XmlNode contextualbody, XDoc doc) {

            // check if this is a no-op
            if(doc.IsEmpty) {
                return;
            }

            // create a sub-buffer for processing
            DekiScriptOutputBuffer buffer = new DekiScriptOutputBuffer(int.MaxValue);

            // push all nodes from the XML document into the buffer
            Stack<XmlNode> stack = new Stack<XmlNode>();

            // check if we're dealing with a simple <html><body> ... </body></html> document
            bool addSiblings = false;
            if((doc.AsXmlNode.NodeType == XmlNodeType.Element) && doc.HasName("html") && doc["head/*"].IsEmpty && doc["tail/*"].IsEmpty && doc["body[@target]"].IsEmpty) {
                var body = doc["body"];
                if(body.IsEmpty || (body.AsXmlNode.ChildNodes.Count == 0)) {

                    // nothing to do
                    return;
                }
                doc = doc[body.AsXmlNode.FirstChild];
                addSiblings = true;
            }

            // loop over nodes
            XmlNode current = doc.AsXmlNode;
            do {
                XmlElement element;
                switch(current.NodeType) {
                case XmlNodeType.Element:
                    element = (XmlElement)current;
                    AppendXmlStart(buffer, element);
                    if(element.HasChildNodes) {
                        stack.Push(addSiblings || (stack.Count > 0) ? current.NextSibling : null);
                        current = element.FirstChild;
                        continue;
                    }
                    buffer.PushXmlEnd();
                    break;
                case XmlNodeType.Attribute:
                    buffer.Push(DekiScriptExpression.Constant((string.IsNullOrEmpty(current.Prefix) ? current.Name : current.Prefix + ":" + current.Name) + "=" + current.Value.QuoteString()));
                    break;
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                case XmlNodeType.Text:
                case XmlNodeType.Whitespace:
                    buffer.Push(DekiScriptExpression.Constant(current.Value));
                    break;
                default:

                    // ignore this node
                    break;
                }

                // move onto next item or resume previous one
                current = addSiblings || (stack.Count > 0) ? current.NextSibling : null;
                while((current == null) && (stack.Count > 0)) {
                    buffer.PushXmlEnd();
                    current = stack.Pop();
                }
            } while(current != null);

            // parse the sub-buffer
            ParseBuffer(buffer, 0, contextualbody, false);
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:67,代码来源:DekiScriptOutputProcessor.cs

示例6: CleanseHtmlDocument

        public static XDoc CleanseHtmlDocument(XDoc html) {
            if(html.HasName("html")) {
                html = html.Clone();

                // remove <head> and <tail> elements
                html["head"].RemoveAll();
                html["tail"].RemoveAll();

                // make sure there is only one body and validate it
                var mainBody = html["body[not(@target)]"];
                if(mainBody.IsEmpty) {
                    html.Elem("body");
                    mainBody = html["body[not(@target)]"];
                }
                foreach(XDoc body in html["body[@target]"]) {
                    body.Remove();
                }
                ValidateXHtml(mainBody, true, true);
            }
            return html;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:21,代码来源:DekiScriptLibrary-Xml.cs

示例7: FromXml

        public static DekiScriptLiteral FromXml(XDoc doc) {

            // check if response is an HTML document
            if(doc.HasName("html")) {

                // TODO (steveb): this handling seems to be to specific to belong here.

                return new DekiScriptList().Add(new DekiScriptXml(doc));
            }

            // check if response is a DekiScript XML document
            if(!doc.HasName("value") || (doc["@type"].AsText == null)) {
                throw new ArgumentException("doc");
            }
            switch(doc["@type"].AsText) {
            case "nil":
                return DekiScriptNil.Value;
            case "bool":
                return Constant(doc.AsBool ?? false);
            case "num":
                return Constant(doc.AsDouble ?? 0.0);
            case "str":
                return Constant(doc.AsText ?? string.Empty);
            case "uri": {
                return Constant(doc.AsUri);
            }
            case "map": {
                DekiScriptMap result = new DekiScriptMap();
                foreach(XDoc value in doc["value"]) {
                    result.Add(value["@key"].AsText, FromXml(value));
                }
                return result;
            }
            case "list": {
                DekiScriptList result = new DekiScriptList();
                foreach(XDoc value in doc["value"]) {
                    result.Add(FromXml(value));
                }
                return result;
            }
            case "xml":
                if((doc.AsXmlNode.ChildNodes.Count == 1) && (doc.AsXmlNode.ChildNodes[0].NodeType == XmlNodeType.Element)) {
                    return new DekiScriptXml(doc[doc.AsXmlNode.ChildNodes[0]]);
                }
                return DekiScriptNil.Value;
            default:
                throw new ArgumentException("doc");
            }
        }
开发者ID:heran,项目名称:DekiWiki,代码行数:49,代码来源:DekiScriptLiteral.cs

示例8: FromXmlRpcToDekiScript

        private static DekiScriptLiteral FromXmlRpcToDekiScript(XDoc xdoc) {
            if(xdoc.HasName("html")) {
                return new DekiScriptList().Add(new DekiScriptXml(xdoc));
            }
            if(xdoc.HasName("methodResponse")) {
                if(!xdoc["fault"].IsEmpty) {
                    string errorMessage = xdoc["fault/value/struct/member[name='faultString']/value/string"].AsText;
                    throw new DekiScriptXmlRpcException(errorMessage ?? xdoc.ToPrettyString());
                }
                if(!xdoc["params"].IsEmpty) {
                    DekiScriptList result = new DekiScriptList();
                    foreach(XDoc param in xdoc["params/param/value"]) {
                        result.Add(ToDekiScriptRecurse(param));
                    }
                    return result;
                } else {

                    // NOTE: unexpected result, treat it as a nil result

                    DekiScriptList result = new DekiScriptList();
                    result.Add(DekiScriptNil.Value);
                    return result;
                }
            }
            throw new DekiScriptUnsupportedTypeException(Location.None, string.Format("<{0}>", xdoc.Name));
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:26,代码来源:DekiScriptXmlRpcInvocationTarget.cs

示例9: Validate

        public static void Validate(XDoc license) {
            try {

                // check if license has a valid element name
                if(!license.HasName("license.public") && !license.HasName("license.private")) {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE, string.Format("Server returned an invalid license document. Expected <license.public>, but received <{0}>.", license.Name));
                }

                // check if license is valid using the public key
                if(!license.HasValidSignature(MindTouchPublicKey)) {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_SIGNATURE, "Server license validation failed. The license signature is not valid.");
                }

                // check license type
                string type = license["@type"].Contents;
                if(!type.EqualsInvariantIgnoreCase("commercial") && !type.EqualsInvariantIgnoreCase("trial")) {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE_TYPE, string.Format("Server license type must be either 'commercial' or 'trial' instead of '{0}'.", type ?? "none"));
                }

                // check license issue date
                DateTime issued = license["date.issued"].AsDate ?? DateTime.MinValue;
                if(issued > DateTime.UtcNow) {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.INVALID_LICENSE, string.Format("Server license has future issue date of {0}.", issued.ToString("dddd, d MMMM yyyy")));
                }

                // check license expiration date
                DateTime expires = license["date.expiration"].AsDate ?? DateTime.MaxValue;
                if(expires < DateTime.UtcNow) {
                    throw new DekiLicenseException(DekiLicenseException.ReasonKind.EXPIRED_LICENSE, string.Format("Server license expired on {0}.", expires.ToString("dddd, d MMMM yyyy")));
                }
            } catch(Exception e) {
                _log.WarnFormat(e.Message);
                throw;
            }
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:35,代码来源:DekiLicense.cs

示例10: ProcessGroupMemberInput

        private static UserBE[] ProcessGroupMemberInput(GroupBE group, XDoc userList) {
            if(!userList.HasName("users")) {
                throw new DreamBadRequestException(DekiResources.EXPECTED_ROOT_NODE_USERS);
            }

            ServiceBE service = ServiceBL.GetServiceById(group.ServiceId);
            if(service == null) {
                throw new DreamInternalErrorException(string.Format("Could not find service with id '{0}' for group name '{1}'. ", group.ServiceId, group.Name));
            }

            //Changing members of an external group is not supported. You may modify members in the external provider instead.
            if(!ServiceBL.IsLocalAuthService(service)) {
                throw new DreamBadRequestException(DekiResources.GROUP_EXTERNAL_CHANGE_MEMBERS);
            }

            UserBE[] members = ReadUserListXml(userList);
            ValidateGroupMemberList(service, members);
            return members;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:19,代码来源:GroupBL.cs

示例11: ProcessPageHeadings

        public static XDoc ProcessPageHeadings(XDoc page) {
            var resources = DekiContext.Current.Resources;
            XDoc content = page.HasName("page") ? page["content"] : page;
            XDoc mainBody = content["body[not(@target)]"];

            // collect all headings from document
            int minHeadingLevel = int.MaxValue;
            List<KeyValuePair<int, XDoc>> headings = new List<KeyValuePair<int, XDoc>>();
            Dictionary<String, int> anchorCounters = new Dictionary<string, int>();

            // select all headings
            var selector = from x in mainBody.VisitOnly(e => !ExcludedTags.Contains(e.AsXmlNode))
                           where IsHeading(x)
                           select x;
            foreach(XDoc heading in selector) {
                int level = int.Parse(heading.Name.Substring(1));
                minHeadingLevel = Math.Min(level, minHeadingLevel);
                headings.Add(new KeyValuePair<int, XDoc>(level, heading));
            }

            // initialize array for heading numbering
            int[] headingNumbering = new int[6] { 0, 0, 0, 0, 0, 0 };
            int maxHeading = DekiContext.Current.Instance.MaxHeadingLevelForTableOfContents;

            // create <div> document
            XDoc result = new XDoc("toc");
            if(headings.Count > 0) {
                int prevLevel = minHeadingLevel;

                // start the containing list here, api is generating some style
                result.Start("ol").Attr("style", "list-style-type:none; margin-left:0px; padding-left:0px;");
                foreach(KeyValuePair<int, XDoc> heading in headings) {
                    int anchorCount;
                    String anchorName = Title.AnchorEncode(heading.Value.AsXmlNode.InnerText);
                    String existingAnchorName = heading.Value["@name"].AsText;
                    heading.Value.RemoveAttr("name");

                    // if an existing anchor name exists that is different from the default anchor name, add it
                    if(!String.IsNullOrEmpty(existingAnchorName) && !existingAnchorName.EqualsInvariant(anchorName)) {
                        heading.Value.AddBefore(new XDoc("span").Attr("id", existingAnchorName));
                    }
                    if(anchorCounters.TryGetValue(anchorName, out anchorCount)) {
                        anchorCounters[anchorName] = ++anchorCount;
                        anchorName = anchorName + "_" + anchorCount;
                    } else {
                        anchorCounters[anchorName] = 1;
                    }

                    // Create the anchor on the page
                    heading.Value.AddBefore(new XDoc("span").Attr("id", anchorName));

                    // check if heading within the toc max heading limit
                    if(heading.Key <= maxHeading) {

                        // check how many <ol> elements we need to create
                        for(int level = prevLevel; level < heading.Key; ++level) {
                            if(result.HasName("ol")) {
                                result.Start("li");
                            }
                            result.Start("ol").Attr("style", "list-style-type:none; margin-left:0px; padding-left:15px;"); // api styles
                        }

                        // check how many <ol> elements we need to close
                        for(int level = prevLevel; level > heading.Key; --level) {
                            headingNumbering[level - 1] = 0;

                            result.End(); // li
                            result.End(); // ol
                        }

                        // check if there was no hierarchy change
                        if(result.HasName("li")) {
                            result.End();
                        }

                        // create new list item
                        ++headingNumbering[heading.Key - 1];
                        string numbering = string.Empty;
                        for(int i = minHeadingLevel; i <= heading.Key; ++i) {
                            if(0 == headingNumbering[i - 1]) {
                                headingNumbering[i - 1] = 1;
                            }
                            numbering += headingNumbering[i - 1] + ".";
                        }

                        result.Start("li");
                        result.Start("span").Value(numbering).End();
                        result.Value(" "); // add a space between the span node and anchor
                        result.Start("a").Attr("href", "#" + anchorName).Attr("rel", "internal").Value(heading.Value.AsXmlNode.InnerText).End();

                        // NOTE (steveb): leave the li tag open so we can insert sub headings

                        prevLevel = heading.Key;
                    }
                }

                // close all open <ol> elements, including first element
                for(int level = prevLevel; level >= minHeadingLevel; --level) {
                    if(result.HasName("li")) {
                        result.End(); // li
//.........这里部分代码省略.........
开发者ID:heran,项目名称:DekiWiki,代码行数:101,代码来源:DekiXmlParser.cs

示例12: ProcessHeadings

        private XDoc ProcessHeadings() {
            XDoc result = null;
            if (!_isInclude) {
                XDoc mainBody = _content[MAIN_BODY_XPATH];
                if (ParserMode.VIEW == _mode || ParserMode.VIEW_NO_EXECUTE == _mode) {

                    // collect all headings from document
                    int minHeadingLevel = int.MaxValue;
                    List<KeyValuePair<int, XDoc>> headings = new List<KeyValuePair<int, XDoc>>();
                    Dictionary<String, int> anchorCounters = new Dictionary<string, int>();

                    // select all headings
                    var selector = from x in mainBody.VisitOnly(e => !ExcludedTags.Contains(e.AsXmlNode)) 
                                   where IsHeading(x) 
                                   select x;
                    foreach (XDoc heading in selector) {
                        int level = int.Parse(heading.Name.Substring(1));
                        minHeadingLevel = Math.Min(level, minHeadingLevel);
                        headings.Add(new KeyValuePair<int, XDoc>(level, heading));
                    }

                    // initialize array for heading numbering
                    int[] headingNumbering = new int[6] { 0, 0, 0, 0, 0, 0 };
                    int maxHeading = DekiContext.Current.Instance.MaxHeadingLevelForTableOfContents;

                    // create <div> document
                    result = new XDoc("toc");
                    if (headings.Count > 0) {
                        int prevLevel = minHeadingLevel;

                        // start the containing list here, api is generating some style
                        result.Start("ol").Attr("style", "list-style-type:none; margin-left:0px; padding-left:0px;");
                        foreach (KeyValuePair<int, XDoc> heading in headings) {
                            int anchorCount;
                            String anchorName = Title.AnchorEncode(heading.Value.AsXmlNode.InnerText);
                            String existingAnchorName = heading.Value["@name"].AsText;
                            heading.Value.RemoveAttr("name");

                            // if an existing anchor name exists that is different from the default anchor name, add it
                            if (!String.IsNullOrEmpty(existingAnchorName) && !existingAnchorName.EqualsInvariant(anchorName)) {
                                heading.Value.AddBefore(new XDoc("span").Attr("id", existingAnchorName));
                            }
                            if (anchorCounters.TryGetValue(anchorName, out anchorCount)) {
                                anchorCounters[anchorName] = ++anchorCount;
                                anchorName = anchorName + "_" + anchorCount;
                            } else {
                                anchorCounters[anchorName] = 1;
                            }

                            // Create the anchor on the page
                            heading.Value.AddBefore(new XDoc("span").Attr("id", anchorName));

                            // check if heading within the toc max heading limit
                            if (heading.Key <= maxHeading) {

                                // check how many <ol> elements we need to create
                                for (int level = prevLevel; level < heading.Key; ++level) {
                                    if (result.HasName("ol")) {
                                        result.Start("li");
                                    }
                                    result.Start("ol").Attr("style", "list-style-type:none; margin-left:0px; padding-left:15px;"); // api styles
                                }

                                // check how many <ol> elements we need to close
                                for (int level = prevLevel; level > heading.Key; --level) {
                                    headingNumbering[level - 1] = 0;

                                    result.End(); // li
                                    result.End(); // ol
                                }

                                // check if there was no hierarchy change
                                if (result.HasName("li")) {
                                    result.End();
                                }

                                // create new list item
                                ++headingNumbering[heading.Key - 1];
                                string numbering = string.Empty;
                                for (int i = minHeadingLevel; i <= heading.Key; ++i) {
                                    if (0 == headingNumbering[i - 1]) {
                                        headingNumbering[i - 1] = 1;
                                    }
                                    numbering += headingNumbering[i - 1] + ".";
                                }

                                result.Start("li");
                                result.Start("span").Value(numbering).End();
                                result.Value(" "); // add a space between the span node and anchor
                                result.Start("a").Attr("href", "#" + anchorName).Attr("rel", "internal").Value(heading.Value.AsXmlNode.InnerText).End();

                                // NOTE (steveb): leave the li tag open so we can insert sub headings

                                prevLevel = heading.Key;
                            }
                        }

                        // close all open <ol> elements, including first element
                        for (int level = prevLevel; level >= minHeadingLevel; --level) {
                            if (result.HasName("li")) {
//.........这里部分代码省略.........
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:101,代码来源:DekiXmlParser.cs

示例13: ReadGrantsXml

        public static List<GrantBE> ReadGrantsXml(XDoc grantsXml, PageBE page, bool ignoreInvalid) {

            List<GrantBE> grants = new List<GrantBE>();
            GrantBE g = null;

            if (!grantsXml.IsEmpty) {
                if (grantsXml.HasName("grant")) {
                    try {
                        g = ReadGrantXml(grantsXml, page);
                    } catch (ArgumentException x) {
                        if (!ignoreInvalid)
                            throw new DreamAbortException(DreamMessage.BadRequest(string.Format(DekiResources.CANNOT_PARSE_GRANTS, x.Message)));
                    }
                    if (g != null) {
                        grants.Add(g);
                    }
                }
                    //If rootnode is grants, pawn off inner xml to GrantFromXml in a loop.
                else if (grantsXml.HasName("grants") || grantsXml.HasName("grants.added") || grantsXml.HasName("grants.removed")) {
                    foreach (XDoc grantXml in grantsXml["grant"]) {
                        try {
                            g = ReadGrantXml(grantXml, page);
                        } catch (ArgumentException x) {
                            if (!ignoreInvalid)
                                throw new DreamAbortException(DreamMessage.BadRequest(string.Format(DekiResources.CANNOT_PARSE_GRANTS, x.Message)));
                        }
                        if (g != null) {
                            grants.Add(g);
                        }
                    }
                }
            }
            return grants;
        }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:34,代码来源:PermissionsBL.cs


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