本文整理汇总了C#中System.Xml.XPath.XPathDocument类的典型用法代码示例。如果您正苦于以下问题:C# XPathDocument类的具体用法?C# XPathDocument怎么用?C# XPathDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPathDocument类属于System.Xml.XPath命名空间,在下文中一共展示了XPathDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: GetTitle
/// <summary>
/// Tries to extract the BluRay title.
/// </summary>
/// <returns></returns>
public string GetTitle()
{
string metaFilePath = Path.Combine(DirectoryBDMV.FullName, @"META\DL\bdmt_eng.xml");
if (!File.Exists(metaFilePath))
return null;
try
{
XPathDocument metaXML = new XPathDocument(metaFilePath);
XPathNavigator navigator = metaXML.CreateNavigator();
if (navigator.NameTable != null)
{
XmlNamespaceManager ns = new XmlNamespaceManager(navigator.NameTable);
ns.AddNamespace("", "urn:BDA:bdmv;disclib");
ns.AddNamespace("di", "urn:BDA:bdmv;discinfo");
navigator.MoveToFirst();
XPathNavigator node = navigator.SelectSingleNode("//di:discinfo/di:title/di:name", ns);
if (node != null)
return node.ToString().Trim();
}
}
catch (Exception e)
{
ServiceRegistration.Get<ILogger>().Error("BDMEx: Meta File Error: ", e);
}
return null;
}
开发者ID:fokion,项目名称:MediaPortal-2,代码行数:31,代码来源:BDInfoExt.cs
示例17: GetDetail
public String GetDetail(String name, String log, DetailEnum detail)
{
String xsl = null;
if (detail == DetailEnum.Summary)
{
return GetSummary(name, log);
}
else if (detail == DetailEnum.Compilation)
{
xsl = GetXslFullFileName("compile.xsl");
}
else if (detail == DetailEnum.Modifications)
{
xsl = GetXslFullFileName("modifications.xsl");
}
else if (detail == DetailEnum.UnitTestsDetail)
{
xsl = GetXslFullFileName("unittests.xsl");
}
else if (detail == DetailEnum.UnitTestsSummary)
{
xsl = GetXslFullFileName("AlternativeNUnitDetails.xsl");
}
String content = cruiseManager.GetLog(name, log);
XPathDocument document = new XPathDocument(new StringReader(content));
return logTransformer.Transform(document, xsl);
}
开发者ID:ralescano,项目名称:castle,代码行数:31,代码来源:ContentTransformation.cs
示例18: AddTargets
private void AddTargets (string map, string input, string baseOutputPath, XPathExpression outputXPath, string link, XPathExpression formatXPath, XPathExpression relativeToXPath) {
XPathDocument document = new XPathDocument(map);
XPathNodeIterator items = document.CreateNavigator().Select("/*/item");
foreach (XPathNavigator item in items) {
string id = (string) item.Evaluate(artIdExpression);
string file = (string) item.Evaluate(artFileExpression);
string text = (string) item.Evaluate(artTextExpression);
id = id.ToLower();
string name = Path.GetFileName(file);
ArtTarget target = new ArtTarget();
target.Id = id;
target.InputPath = Path.Combine(input, file);
target.baseOutputPath = baseOutputPath;
target.OutputXPath = outputXPath;
if (string.IsNullOrEmpty(name)) target.LinkPath = link;
else target.LinkPath = string.Format("{0}/{1}", link, name);
target.Text = text;
target.Name = name;
target.FormatXPath = formatXPath;
target.RelativeToXPath = relativeToXPath;
targets[id] = target;
// targets.Add(id, target);
}
}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:33,代码来源:ResolveArtLinksComponent.cs
示例19: Main
static int Main(string[] args)
{
Console.WriteLine("XMLTo v0.1 [www.mosa-project.org]");
Console.WriteLine("Copyright 2009 by the MOSA Project. Licensed under the New BSD License.");
Console.WriteLine("Written by Philipp Garcia ([email protected])");
Console.WriteLine();
Console.WriteLine("Usage: XMLTo <xml file> <xsl file> <output file>");
Console.WriteLine();
if (args.Length < 3)
{
Console.Error.WriteLine("ERROR: Missing arguments");
return -1;
}
try {
XPathDocument myXPathDoc = new XPathDocument(args[0]);
XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load(args[1]);
XmlTextWriter myWriter = new XmlTextWriter(args[2], null);
myXslTrans.Transform(myXPathDoc, null, myWriter);
return 0;
}
catch (Exception e) {
Console.Error.WriteLine("Exception: {0}", e.ToString());
return -1;
}
}
开发者ID:hj1980,项目名称:Mosa,代码行数:29,代码来源:Program.cs
示例20: AutoUpdateHepler
static AutoUpdateHepler()
{
string str = FileUtility.ApplicationRootPath + @"\update";
if (LoggingService.IsInfoEnabled)
{
LoggingService.Info("读取升级配置:" + str);
}
XmlConfigSource source = null;
if (System.IO.File.Exists(str + ".cxml"))
{
XmlTextReader decryptXmlReader = new CryptoHelper(CryptoTypes.encTypeDES).GetDecryptXmlReader(str + ".cxml");
IXPathNavigable document = new XPathDocument(decryptXmlReader);
source = new XmlConfigSource(document);
decryptXmlReader.Close();
}
else if (System.IO.File.Exists(str + ".xml"))
{
source = new XmlConfigSource(str + ".xml");
}
if (source != null)
{
softName = source.Configs["FtpSetting"].GetString("SoftName", string.Empty);
version = source.Configs["FtpSetting"].GetString("Version", string.Empty);
server = source.Configs["FtpSetting"].GetString("Server", string.Empty);
user = source.Configs["FtpSetting"].GetString("User", string.Empty);
password = source.Configs["FtpSetting"].GetString("Password", string.Empty);
path = source.Configs["FtpSetting"].GetString("Path", string.Empty);
liveup = source.Configs["FtpSetting"].GetString("LiveUp", string.Empty);
autoupdate = source.Configs["FtpSetting"].GetString("autoupdate", string.Empty);
}
}
开发者ID:vanloc0301,项目名称:mychongchong,代码行数:31,代码来源:AutoUpdateHepler.cs
注:本文中的System.Xml.XPath.XPathDocument类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论