本文整理汇总了C#中System.Xml.XPath.XPathDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# XPathDocument.CreateNavigator方法的具体用法?C# XPathDocument.CreateNavigator怎么用?C# XPathDocument.CreateNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathDocument
的用法示例。
在下文中一共展示了XPathDocument.CreateNavigator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadDelegates
public void ReadDelegates(string file, DelegateCollection delegates, string apiname, string apiversions)
{
var specs = new XPathDocument(file);
// The pre-GL4.4 spec format does not distinguish between
// different apinames (it is assumed that different APIs
// are stored in distinct signature.xml files).
// To maintain compatibility, we detect the version of the
// signatures.xml file and ignore apiname if it is version 1.
var specversion = GetSpecVersion(specs);
if (specversion == "1")
{
apiname = null;
}
foreach (var apiversion in apiversions.Split('|'))
{
string xpath_add, xpath_delete;
GetSignaturePaths(apiname, apiversion, out xpath_add, out xpath_delete);
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_delete))
{
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
delegates.Remove(node.GetAttribute("name", String.Empty));
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select(xpath_add))
{
delegates.AddRange(ReadDelegates(nav, apiversion));
}
}
}
示例2: Main
static void Main(string[] args)
{
PerfTest perf = new PerfTest();
int repeat = 1000;
perf.Start();
XPathDocument doc = new XPathDocument(Globals.GetResource(Globals.NorthwindResource));
//XmlDocument doc = new XmlDocument();
//doc.Load("test/northwind.xml");
Console.WriteLine("Loading XML document: {0, 6:f2} ms", perf.Stop());
XPathNavigator nav = doc.CreateNavigator();
XPathExpression expr = nav.Compile("/ROOT/CustomerIDs/OrderIDs/Item[OrderID=' 10330']/ShipAddress");
Console.WriteLine("Regular selection, warming...");
SelectNodes(nav, repeat, perf, expr);
Console.WriteLine("Regular selection, testing...");
SelectNodes(nav, repeat, perf, expr);
perf.Start();
IndexingXPathNavigator inav = new IndexingXPathNavigator(
doc.CreateNavigator());
Console.WriteLine("Building IndexingXPathNavigator: {0, 6:f2} ms", perf.Stop());
perf.Start();
inav.AddKey("orderKey", "OrderIDs/Item", "OrderID");
Console.WriteLine("Adding keys: {0, 6:f2} ms", perf.Stop());
XPathExpression expr2 = inav.Compile("key('orderKey', ' 10330')/ShipAddress");
perf.Start();
inav.BuildIndexes();
Console.WriteLine("Indexing: {0, 6:f2} ms", perf.Stop());
Console.WriteLine("Indexed selection, warming...");
SelectIndexedNodes(inav, repeat, perf, expr2);
Console.WriteLine("Indexed selection, testing...");
SelectIndexedNodes(inav, repeat, perf, expr2);
}
示例3: ReadDelegates
public void ReadDelegates(string file, DelegateCollection delegates)
{
var specs = new XPathDocument(file);
foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/delete"))
{
foreach (XPathNavigator node in nav.SelectChildren("function", String.Empty))
delegates.Remove(node.GetAttribute("name", String.Empty));
}
foreach (XPathNavigator nav in specs.CreateNavigator().Select("/signatures/add"))
{
Utilities.Merge(delegates, ReadDelegates(nav));
}
}
示例4: CancelAppointment
public bool CancelAppointment(HackExchangeContext context, CalendarItem appointment)
{
var url = context.Endpoint;
var request = new HttpRequestMessage(HttpMethod.Post, url);
var postBodyTemplate = LoadXml("CancelAppointment");
var postBody = string.Format(postBodyTemplate, appointment.Id, appointment.ChangeKey);
request.Content = new StringContent(postBody, Encoding.UTF8, "text/xml");
var clientHandler = new HttpClientHandler()
{
Credentials = context.Credentials
};
using (var client = new HttpClient(clientHandler))
{
var response = client.SendAsync(request).Result;
var responseBody = response.Content.ReadAsStringAsync().Result;
var doc = new XPathDocument(new StringReader(responseBody));
var nav = doc.CreateNavigator();
var nsManager = new XmlNamespaceManager(nav.NameTable);
nsManager.AddNamespace("m", "http://schemas.microsoft.com/exchange/services/2006/messages");
nsManager.AddNamespace("t", "http://schemas.microsoft.com/exchange/services/2006/types");
var responseClass = EvaluateXPath(nav, nsManager, "//m:DeleteItemResponseMessage/@ResponseClass");
return responseClass == "Success";
}
}
示例5: ResinConf
public ResinConf(String file)
{
_xPathDoc = new XPathDocument(file);
_docNavigator = _xPathDoc.CreateNavigator();
_xmlnsMgr = new XmlNamespaceManager(_docNavigator.NameTable);
_xmlnsMgr.AddNamespace("caucho", "http://caucho.com/ns/resin");
}
示例6: PackageInstaller
/// -----------------------------------------------------------------------------
/// <summary>
/// This Constructor creates a new PackageInstaller instance
/// </summary>
/// <param name="package">A PackageInfo instance</param>
/// <history>
/// [cnurse] 01/21/2008 created
/// </history>
/// -----------------------------------------------------------------------------
public PackageInstaller(PackageInfo package)
{
IsValid = true;
DeleteFiles = Null.NullBoolean;
Package = package;
if (!string.IsNullOrEmpty(package.Manifest))
{
//Create an XPathDocument from the Xml
var doc = new XPathDocument(new StringReader(package.Manifest));
XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("package");
ReadComponents(nav);
}
else
{
ComponentInstallerBase installer = InstallerFactory.GetInstaller(package.PackageType);
if (installer != null)
{
//Set package
installer.Package = package;
//Set type
installer.Type = package.PackageType;
_componentInstallers.Add(0, installer);
}
}
}
示例7: 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);
}
}
示例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;
}
}
示例9: DoFindAlbums
public static List<Album> DoFindAlbums(string artistId, string artistName)
{
string uri = string.Format("http://musicbrainz.org/ws/1/artist/{0}?type=xml&inc=sa-Official+release-events", artistId);
XPathDocument doc = new XPathDocument(uri);
XPathNavigator nav = doc.CreateNavigator();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);
string ns = "http://musicbrainz.org/ns/mmd-1.0#";
nsmgr.AddNamespace("mb", ns);
XPathNodeIterator ni = nav.Select("//mb:release", nsmgr);
List<Album> albums = new List<Album>();
while (ni.MoveNext())
{
XPathNavigator current = ni.Current;
Album album = new Album();
album.Artist = artistName;
album.Id = current.GetAttribute("id", string.Empty);
current.MoveToChild("title", ns);
album.Title = HttpUtility.HtmlDecode(current.InnerXml);
current.MoveToParent();
if (current.MoveToChild("asin", ns))
album.Asin = current.InnerXml;
current.MoveToParent();
if (current.MoveToChild("release-event-list", ns))
{
current.MoveToChild("event", ns);
string s = current.GetAttribute("date", string.Empty); // month and day may be missing
album.Date = GetDate(s);
}
current.MoveToChild("title", ns);
albums.Add(album);
}
return albums;
}
示例10: Load
public mdnaSettings.Settings Load( string category )
{
mdnaSettings.Settings result = new mdnaSettings.Settings();
XPathDocument doc = new XPathDocument( m_fileName );
XPathNavigator nav = doc.CreateNavigator();
// Get the expression compiled.
// We want all of the nodes in the category regardless of position or their attributes.
XPathExpression expr;
expr = nav.Compile( "//"+category );
XPathNodeIterator iter = nav.Select(expr);
result.Category = category;
try
{
while( iter.MoveNext() )
{
result.Add( iter.Current.GetAttribute( "name", "" ), iter.Current.GetAttribute( "value", "" ) );
}
}
catch( Exception ex )
{
MessageBox.Show( "Exception Caught: " + ex.Message );
}
return( result );
}
示例11: BuildVerifier
protected BuildVerifier()
{
this.m_UnsupportedAssemblies = new Dictionary<string, HashSet<string>>();
string text = Path.Combine(Path.Combine(EditorApplication.applicationContentsPath, "Resources"), "BuildVerification.xml");
XPathDocument xPathDocument = new XPathDocument(text);
XPathNavigator xPathNavigator = xPathDocument.CreateNavigator();
xPathNavigator.MoveToFirstChild();
XPathNodeIterator xPathNodeIterator = xPathNavigator.SelectChildren("assembly", string.Empty);
while (xPathNodeIterator.MoveNext())
{
string attribute = xPathNodeIterator.Current.GetAttribute("name", string.Empty);
if (attribute == null || attribute.Length < 1)
{
throw new ApplicationException(string.Format("Failed to load {0}, <assembly> name attribute is empty", text));
}
string text2 = xPathNodeIterator.Current.GetAttribute("platform", string.Empty);
if (text2 == null || text2.Length < 1)
{
text2 = "*";
}
if (!this.m_UnsupportedAssemblies.ContainsKey(text2))
{
this.m_UnsupportedAssemblies.Add(text2, new HashSet<string>());
}
this.m_UnsupportedAssemblies[text2].Add(attribute);
}
}
示例12: ReadXml
/// <summary>
/// Generates an object from its XML representation.
/// </summary>
/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
public override void ReadXml(System.Xml.XmlReader reader)
{
XPathDocument doc = new XPathDocument(reader);
XPathNavigator nav = doc.CreateNavigator();
XPathNavigator iter = nav.SelectSingleNode("Metric/MetricName");
if (iter != null)
MetricName = iter.Value;
iter = nav.SelectSingleNode("Metric/Description");
if (iter != null)
Description = iter.Value;
var serializer = TraceLab.Core.Serialization.XmlSerializerFactory.GetSerializer(typeof(Point), null);
iter = nav.SelectSingleNode("Metric/Points");
if (iter != null)
{
m_points = new List<Point>();
XPathNodeIterator pointsNodes = iter.Select("Point");
while (pointsNodes.MoveNext())
{
var p = (Point)serializer.Deserialize(pointsNodes.Current.ReadSubtree());
m_points.Add(p);
}
}
}
示例13: ReadXml
/// <summary>
/// Generates an object from its XML representation.
/// </summary>
/// <param name="reader">The <see cref="T:System.Xml.XmlReader"/> stream from which the object is deserialized.</param>
public override void ReadXml(XmlReader reader)
{
if (reader == null)
throw new ArgumentNullException("reader");
if (reader.LocalName == "DirectoryPath")
{
XmlReader subReader = reader.ReadSubtree();
XPathDocument doc = new XPathDocument(subReader);
var nav = doc.CreateNavigator();
XPathNavigator iter = nav.SelectSingleNode("/DirectoryPath/Version");
if (iter != null)
{
long ver = iter.ValueAsLong;
if (ver == CurrentVersion)
{
ReadCurrentVersion(nav);
}
else
{
throw new NotSupportedException("Version not supported.");
}
}
else
{
throw new NotSupportedException("Could not read version of DirectoryPath. ");
}
}
}
示例14: Setting_the_cache_option_causes_the_results_to_be_cached_in_the_default_directory
public void Setting_the_cache_option_causes_the_results_to_be_cached_in_the_default_directory()
{
// arrange
var resultsFile = "StyleCop.Cache";
System.IO.File.Delete(resultsFile);
// create the activity
var target = new StyleCop();
// create a parameter set
Dictionary<string, object> args = new Dictionary<string, object>
{
{ "SourceFiles", new string[] { @"TestFiles\FileWith6Errors.cs" } },
{ "SettingsFile", @"TestFiles\AllSettingsEnabled.StyleCop" },
{ "CacheResults", true },
};
// Create a WorkflowInvoker and add the IBuildDetail Extension
WorkflowInvoker invoker = new WorkflowInvoker(target);
// act
var results = invoker.Invoke(args);
// assert
Assert.IsTrue(System.IO.File.Exists(resultsFile));
var document = new XPathDocument(resultsFile);
var nav = document.CreateNavigator();
Assert.AreEqual(6d, nav.Evaluate("count(/stylecopresultscache/sourcecode/violations/violation)"));
}
示例15: GetTimeZone
/// <summary>
/// Gets the time zone.
/// </summary>
/// <param name="offset">The offset.</param>
/// <returns></returns>
private static string GetTimeZone(double offset)
{
//Adjust result based on the server time zone
string timeZoneKey = "timeOffset" + offset.ToString("F");
string result = (CallContext.GetData(timeZoneKey) ?? "").ToString();
if (result.Length == 0)
{
string zonesDocPath = "TimeZones.xml";
XPathDocument timeZonesDoc = new XPathDocument(zonesDocPath);
try
{
string xPath = "/root/option[@value='" + offset.ToString("F") + "']";
XPathNavigator searchNavigator = timeZonesDoc.CreateNavigator();
XmlNamespaceManager nsmgr = new XmlNamespaceManager(searchNavigator.NameTable);
XPathNodeIterator iterator = searchNavigator.Select(xPath, nsmgr);
if (iterator.MoveNext())
{
result = iterator.Current.Value;
if (!string.IsNullOrEmpty(result))
{
CallContext.SetData(timeZoneKey, result);
}
}
}
catch (Exception ex)
{
return ex.Message;
}
}
return result;
}