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


C# XPath.XPathDocument类代码示例

本文整理汇总了C#中System.Xml.XPath.XPathDocument的典型用法代码示例。如果您正苦于以下问题:C# XPathDocument类的具体用法?C# XPathDocument怎么用?C# XPathDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XPathDocument类属于System.Xml.XPath命名空间,在下文中一共展示了XPathDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessRecord

        /// <summary>
        /// Processes the record.
        /// </summary>
        protected override void ProcessRecord()
        {
            this.WriteVerbose("Formatting log");
            using (var xmlReader = new StringReader(this.Log))
            {
                var xpath = new XPathDocument(xmlReader);
                using (var writer = new StringWriter())
                {
                    var transform = new XslCompiledTransform();
                    Func<string, string> selector = file => !Path.IsPathRooted(file) ? Path.Combine(Environment.CurrentDirectory, file) : file;
                    foreach (var fileToLoad in this.FormatFile.Select(selector))
                    {
                        this.WriteVerbose("Loading format file " + fileToLoad);
                        using (var stream = File.OpenRead(fileToLoad))
                        {
                            using (var reader = XmlReader.Create(stream))
                            {
                                transform.Load(reader);
                                transform.Transform(xpath, null, writer);
                            }
                        }
                    }

                    this.WriteObject(writer.GetStringBuilder().ToString(), false);
                }
            }
        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:30,代码来源:FormatLog.cs

示例2: ReadDocument

		private ContentItem ReadDocument(XPathDocument xpd)
		{
			XPathNavigator navigator = xpd.CreateNavigator();
			OnMovingToRootItem(navigator);

			return OnReadingItem(navigator);
		}
开发者ID:grbbod,项目名称:drconnect-jungo,代码行数:7,代码来源:N2XmlReader.cs

示例3: GetTweets

        public string GetTweets()
        {
            // Uppgift 6:
            var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager);
            XPathDocument updates = new XPathDocument(TwitterConsumer.GetUpdates(twitter, this.AccessToken).CreateReader());
            XPathNavigator nav = updates.CreateNavigator();
            var parsedUpdates = from status in nav.Select("/statuses/status").OfType<XPathNavigator>()
                                where !status.SelectSingleNode("user/protected").ValueAsBoolean
                                select new
                                {
                                    User = status.SelectSingleNode("user/name").InnerXml,
                                    Status = status.SelectSingleNode("text").InnerXml,
                                };

            StringBuilder tableBuilder = new StringBuilder();
            tableBuilder.Append("<table><tr><td>Name</td><td>Update</td></tr>");

            foreach (var update in parsedUpdates)
            {
                tableBuilder.AppendFormat(
                    "<tr><td>{0}</td><td>{1}</td></tr>",
                    HttpUtility.HtmlEncode(update.User),
                    HttpUtility.HtmlEncode(update.Status));
            }
            tableBuilder.Append("</table>");
            return tableBuilder.ToString();
        }
开发者ID:awt2gbg2012,项目名称:Lektion19,代码行数:27,代码来源:HomeController.cs

示例4: OnLoad

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            var resourcefile = Server.MapPath(LocalResourceFile + ".ascx.resx");
            if (File.Exists(resourcefile))
            {
                var document = new XPathDocument(resourcefile);
                var navigator = document.CreateNavigator();

                var nodes = navigator.Select("/root/data[starts-with(@name, 'WhatsNew')]/@name");

                var releasenotes = new List<ReleaseInfo>();

                while (nodes.MoveNext())
                {
                    var key = nodes.Current.Value;
                    var version = string.Format(Localization.GetString("notestitle.text", LocalResourceFile), key.Replace("WhatsNew.", string.Empty));
                    releasenotes.Add(new ReleaseInfo(Localization.GetString(key, LocalResourceFile), version));
                }

                releasenotes.Sort(CompareReleaseInfo);

                WhatsNewList.DataSource = releasenotes;
                WhatsNewList.DataBind();

                header.InnerHtml = Localization.GetString("header.text", LocalResourceFile);
                footer.InnerHtml = Localization.GetString("footer.text", LocalResourceFile);
            }
        }
开发者ID:hackoose,项目名称:cfi-team05,代码行数:29,代码来源:WhatsNew.ascx.cs

示例5: PopulateTree

		public override void PopulateTree (Tree tree)
		{
			XPathNavigator n = new XPathDocument (Path.Combine (basedir, "toc.xml")).CreateNavigator ();
			n.MoveToRoot ();
			n.MoveToFirstChild ();
			PopulateNode (n.SelectChildren ("node", ""), tree.RootNode);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:ecmaspec-provider.cs

示例6: Transform

        public static string Transform(string xml, string xslPath)
        {
            try
            {
                //create an XPathDocument using the reader containing the XML
                MemoryStream m = new MemoryStream(System.Text.Encoding.Default.GetBytes(xml));

                XPathDocument xpathDoc = new XPathDocument(new StreamReader(m));

                //Create the new transform object
                XslCompiledTransform transform = new XslCompiledTransform();

                //String to store the resulting transformed XML
                StringBuilder resultString = new StringBuilder();

                XmlWriter writer = XmlWriter.Create(resultString);

                transform.Load(xslPath);

                transform.Transform(xpathDoc,writer);
               
                return resultString.ToString();
            }
            catch (Exception e)
            {

                Console.WriteLine("Exception: {0}", e.ToString());
                return e.ToString();
            }
        }
开发者ID:mastronardif,项目名称:AngularAndMVC,代码行数:30,代码来源:MyXML.cs

示例7: Transform

        private static StringBuilder Transform(string gcmlPath)
        {
            if(!File.Exists(gcmlPath))
            {
                throw new GCMLFileNotFoundException("The GCML File" + gcmlPath + " does not exist.");
            }

            if(!File.Exists(xsltFilePath))
            {
                throw new XSLTFileNotFoundException("The XSLT File" + xsltFilePath + " does not exist.");
            }

            StringBuilder sb = new StringBuilder();
            XmlTextReader xmlSource = new XmlTextReader(gcmlPath);
            XPathDocument xpathDoc = new XPathDocument(xmlSource);
            XslCompiledTransform xsltDoc = new XslCompiledTransform();

            xsltDoc.Load(xsltFilePath);

            StringWriter sw = new StringWriter(sb);
            try
            {
                xsltDoc.Transform(xpathDoc, null, sw);
            }
            catch (XsltException except)
            {
                Console.WriteLine(except.Message);
                throw except;
            }

            return sb;
        }
开发者ID:radtek,项目名称:rrcomssys-team-5,代码行数:32,代码来源:SchemaTransformer.cs

示例8: foreach

        /// <inheritdoc />
        public override XPathNavigator this[string key]
        {
            get
            {
                string xml;

                // Try the in-memory cache first
                XPathNavigator content = base[key];

                // If not found there, try the database caches if there are any
                if(content == null && esentCaches.Count != 0)
                    foreach(var c in esentCaches)
                        if(c.TryGetValue(key, out xml))
                        {
                            // Convert the XML to an XPath navigator
                            using(StringReader textReader = new StringReader(xml))
                                using(XmlReader reader = XmlReader.Create(textReader, settings))
                                {
                                    XPathDocument document = new XPathDocument(reader);
                                    content = document.CreateNavigator();
                                }
                        }

                return content;
            }
        }
开发者ID:modulexcite,项目名称:SHFB-1,代码行数:27,代码来源:ESentIndexCache.cs

示例9: GetKeyboardLayoutType

        public KeyboardLayoutType GetKeyboardLayoutType(string locale)
        {
            if (String.IsNullOrEmpty(locale))
                return KeyboardLayoutType.US;

            // Get the layout type - US, European etc. The locale in the XML file must be upper case!
            string expression = @"/keyboards/keyboard[locale='" + locale.ToUpper(CultureInfo.InvariantCulture) + "']";

            XPathNodeIterator iterator;

            using (Stream xmlstream = GetXMLDocumentAsStream(_keyboardfilename))
            {
                XPathDocument document = new XPathDocument(xmlstream);
                XPathNavigator nav = document.CreateNavigator();

                iterator = nav.Select(expression);
            }

            int value = 0; // Default to US 

            if (iterator.Count == 1)
            {
                iterator.MoveNext();
                string layout = GetElementValue("layout", iterator.Current);
                if (String.IsNullOrEmpty(layout) == false)
                {
                    value = Int32.Parse(layout, CultureInfo.InvariantCulture.NumberFormat);
                }
            }

            return (KeyboardLayoutType)value;
        }
开发者ID:tmzu,项目名称:keymapper,代码行数:32,代码来源:keydataxml.cs

示例10: RunXslt

        public void RunXslt(String xsltFile, String xmlDataFile, String outputXml)
        {
            XPathDocument input = new XPathDocument(xmlDataFile);

            XslTransform myXslTrans = new XslTransform() ;
            XmlTextWriter output = null;
            try
            {
                myXslTrans.Load(xsltFile);

                output = new XmlTextWriter(outputXml, null);
                output.Formatting = Formatting.Indented;

                myXslTrans.Transform(input, null, output);

            }
            catch (Exception e)
            {
                String msg = e.Message;
                if (msg.IndexOf("InnerException") >0)
                {
                    msg = e.InnerException.Message;
                }

                MessageBox.Show("Error: " + msg + "\n" + e.StackTrace, "Xslt Error File: " + xsltFile, MessageBoxButtons.OK, MessageBoxIcon.Error);

            }
            finally
            {
                try { output.Close(); }
                catch (Exception) { }
            }
        }
开发者ID:kcsampson,项目名称:Kexplorer,代码行数:33,代码来源:XSLTRunScript.cs

示例11: ReadPersistentFormData

 /// <summary>
 /// Read and apply persistent form display data (Size, Position, and WindowState)
 /// </summary>
 /// <param name="form">Form to be set</param>
 internal static void ReadPersistentFormData(System.Windows.Forms.Form form)
 {
     try {
         StreamReader reader = new StreamReader(Application.ExecutablePath + ".formdata.xml", Encoding.UTF8);
         XPathDocument doc = new XPathDocument(reader);
         XPathNavigator nav = doc.CreateNavigator();
         try {
             XPathNodeIterator iterator = nav.Select(String.Format("//Forms/{0}/PersistentData", form.Name));
             iterator.MoveNext();
             form.WindowState = (FormWindowState)Enum.Parse(form.WindowState.GetType(), iterator.Current.GetAttribute("WindowState",	""), false);
             if (form.WindowState == FormWindowState.Normal) {
                 form.Top	= Convert.ToInt16(iterator.Current.GetAttribute("Top",		"").ToString());
                 form.Left	= Convert.ToInt16(iterator.Current.GetAttribute("Left",		"").ToString());
                 form.Width	= Convert.ToInt16(iterator.Current.GetAttribute("Width",	"").ToString());
                 form.Height	= Convert.ToInt16(iterator.Current.GetAttribute("Height",	"").ToString());
             }
         }
         catch {
         }
         finally {
             reader.Close();
         }
     }
     catch {
     }
 }
开发者ID:MickaelE,项目名称:DaBCoS9,代码行数:30,代码来源:Utils.cs

示例12: LoadFile

 public override void LoadFile(Stream stream)
 {
     string p = AnnotationPlugIn.GenerateDataRecordPath();
     // t|1|OrderDetails,_Annotation_Attachment20091219164153Z|10248|11
     Match m = Regex.Match(this.Value, "_Annotation_Attachment(\\w+)\\|");
     string fileName = Path.Combine(p, (m.Groups[1].Value + ".xml"));
     XPathNavigator nav = new XPathDocument(fileName).CreateNavigator().SelectSingleNode("/*");
     fileName = Path.Combine(p, ((Path.GetFileNameWithoutExtension(fileName) + "_")
                     + Path.GetExtension(nav.GetAttribute("fileName", String.Empty))));
     if (!(this.Value.StartsWith("t|")))
     {
         this.ContentType = nav.GetAttribute("contentLength", String.Empty);
         HttpContext.Current.Response.ContentType = this.ContentType;
     }
     this.FileName = nav.GetAttribute("fileName", String.Empty);
     Stream input = File.OpenRead(fileName);
     try
     {
         byte[] buffer = new byte[(1024 * 64)];
         long offset = 0;
         long bytesRead = input.Read(buffer, 0, buffer.Length);
         while (bytesRead > 0)
         {
             stream.Write(buffer, 0, Convert.ToInt32(bytesRead));
             offset = (offset + bytesRead);
             bytesRead = input.Read(buffer, 0, buffer.Length);
         }
     }
     finally
     {
         input.Close();
     }
 }
开发者ID:mehedi09,项目名称:GridWork,代码行数:33,代码来源:AnnotationPlugIn.cs

示例13: XPathUtils

        static XPathUtils()
        {
            XmlDocument doc = new XmlDocument();
              doc.AppendChild(doc.CreateElement("DocumentRoot"));

              _emptyXPathDocument = new XPathDocument(new XmlNodeReader(doc));
        }
开发者ID:okyereadugyamfi,项目名称:softlogik,代码行数:7,代码来源:XPathUtils.cs

示例14: GetTextLocationOfXmlNode

        /// <summary>
        /// Returns the line number and line position of the specified XML node.
        /// </summary>
        /// <param name="xmlFileFullPathName">The fully qualified path name to the XML file.</param>
        /// <param name="xpath">The XPath of the XML node to get the location of.</param>
        /// <param name="lineNumber">If the return value is true, the line number of the specified XML element.</param>
        /// <param name="linePosition">If the return value is true, the posiiton on the line of the specified XML element.</param>
        /// <returns>True if the element is found, otherwise false.</returns>
        public static bool GetTextLocationOfXmlNode(string xmlFileFullPathName, string xpath, out int lineNumber, out int linePosition)
        {
            bool isElementFound;
            XPathDocument xpathSlashDoc = new XPathDocument(xmlFileFullPathName);
            XPathNavigator navSlashDoc = xpathSlashDoc.CreateNavigator();
            XPathNodeIterator itr = navSlashDoc.Select(xpath);
            if (itr.Count > 0 && itr.MoveNext())
            {
                IXmlLineInfo lineInfo = itr.Current as IXmlLineInfo;
                DiagnosticService.Assert(lineInfo != null, "Line Information not available.");

                if (lineInfo != null)
                {
                    lineNumber = lineInfo.LineNumber;
                    linePosition = lineInfo.LinePosition;
                }
                else
                {
                    lineNumber = -1;
                    linePosition = -1;
                }
                Debug.WriteLine(itr.Current.Name + "(" + lineNumber + ","+ linePosition +")");
                isElementFound = true;
            }
            else
            {
                lineNumber = -1;
                linePosition = -1;
                isElementFound = false;
            }
            return isElementFound;
        }
开发者ID:IssamElbaytam,项目名称:slashdocs,代码行数:40,代码来源:XmlTools.cs

示例15: Episode

        public Episode(FileInfo file, Season seasonparent)
            : base(file.Directory)
        {
            String xmlpath = file.Directory.FullName + "/metadata/" + Path.GetFileNameWithoutExtension(file.FullName) + ".xml";
            if (!File.Exists(xmlpath))
            {
                Valid = false;
                return;
            }
            EpisodeXml = new XPathDocument(xmlpath);
            EpisodeNav = EpisodeXml.CreateNavigator();
            EpisodeFile = file;

            _season = seasonparent;

            transX = 200;
            transY = 100;

            backdropImage = _season.backdropImage;

            XPathNodeIterator nodes = EpisodeNav.Select("//EpisodeID");
            nodes.MoveNext();
            folderImage = file.Directory.FullName + "/metadata/" + nodes.Current.Value + ".jpg";

            if (!File.Exists(folderImage))
                folderImage = "/Images/nothumb.jpg";
            title = this.asTitle();

            videoURL = EpisodeFile.FullName;

            LoadImage(folderImage);
        }
开发者ID:fivesixty,项目名称:StandaloneMB,代码行数:32,代码来源:Episode.cs


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