本文整理汇总了C#中System.Xml.XmlDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateNavigator方法的具体用法?C# XmlDocument.CreateNavigator怎么用?C# XmlDocument.CreateNavigator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateNavigator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: List1
public void List1()
{
string xml = @"<?xml version='1.0'?>
<root>
<element>1</element>
<element></element>
<element/>
<element>2</element>
</root>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
XPathNodeIterator iterator = doc.CreateNavigator().Select("//element");
XmlNodeList list = XmlNodeListFactory.CreateNodeList(iterator);
int count = 0;
foreach (XmlNode n in list)
{
count++;
}
Assert.AreEqual(4, count);
iterator = doc.CreateNavigator().Select("//element");
list = XmlNodeListFactory.CreateNodeList(iterator);
Assert.AreEqual(4, list.Count);
}
示例2: Apply
public void Apply (XmlDocument targetDocument, IXmlNamespaceResolver context) {
XPathExpression local_file_expression = file_expression.Clone();
local_file_expression.SetContext(context);
XPathExpression local_source_expression = source_expression.Clone();
local_source_expression.SetContext(context);
XPathExpression local_target_expression = target_expression.Clone();
local_target_expression.SetContext(context);
string file_name = (string) targetDocument.CreateNavigator().Evaluate(local_file_expression);
string file_path = Path.Combine(root_directory, file_name);
if (!File.Exists(file_path)) return;
XPathDocument sourceDocument = new XPathDocument(file_path);
XPathNavigator target_node = targetDocument.CreateNavigator().SelectSingleNode(local_target_expression);
if (target_node == null) return;
XPathNodeIterator source_nodes = sourceDocument.CreateNavigator().Select(local_source_expression);
foreach (XPathNavigator source_node in source_nodes) {
target_node.AppendChild(source_node);
}
}
示例3: EqualNavigators
public void EqualNavigators()
{
XmlDocument doc = new XmlDocument();
doc.LoadXml( @"
<root xmlns:u='uuu'>
<u:element1 attr1='1' attr2='b'>
<subelement1>uhus</subelement1>
<!-- uhus was here -->
</u:element1>
</root>
<!-- and here -->
" );
NavigatorUtils.AreEqual( doc.CreateNavigator(), doc.CreateNavigator() );
}
示例4: load
private void load(string config_file)
{
XmlDocument document = new XmlDocument();
try
{
document.Load(config_file);
XPathNavigator navigator = document.CreateNavigator();
XPathNodeIterator iterator = (XPathNodeIterator)
navigator.Evaluate("config/*");
while (iterator.MoveNext())
{
XPathNavigator element = iterator.Current;
switch (element.Name)
{
case "src2srcml-path":
src2srcml_path = element.Value;
break;
}
}
}
catch (Exception e)
{
throw e;
}
}
示例5: XmlDocument
/// <exception cref="BetOMaticException"/>
XmlDocument IBetOMaticService.FindEvents(string[] keywords, int startIndex, int count, bool commentInfo)
{
XmlDocument xmlDocument = new XmlDocument();
try
{
xmlDocument.Load(String.Format(betomaticFindEventsUri, String.Join("+", keywords), startIndex, count));
if (commentInfo)
{
/* Add the number of comments to each event */
XPathNavigator navigator = xmlDocument.CreateNavigator();
XPathNodeIterator iterator = navigator.Select("//event");
while (iterator.MoveNext())
{
XPathNodeIterator itId = iterator.Current.Select("./id");
itId.MoveNext();
int numberOfComments = CommentDao.GetNumberOfCommentsByEvent(int.Parse(itId.Current.InnerXml));
iterator.Current.AppendChildElement("", "numberOfComments", "", numberOfComments.ToString());
}
}
}
catch (FileNotFoundException)
{
throw new BetOMaticException();
}
catch (WebException)
{
throw new BetOMaticException();
}
return xmlDocument;
}
示例6: op_Evaluate_XPathNavigator_stringNull
public void op_Evaluate_XPathNavigator_stringNull()
{
var xml = new XmlDocument();
xml.LoadXml("<foo>bar</foo>");
Assert.Throws<ArgumentNullException>(() => xml.CreateNavigator().Evaluate<string>(null));
}
示例7: op_Evaluate_XPathNavigator_string
public void op_Evaluate_XPathNavigator_string()
{
var xml = new XmlDocument();
xml.LoadXml("<foo>bar</foo>");
Assert.True(xml.CreateNavigator().Evaluate<bool>("1=count(/foo[text()='bar'])"));
}
示例8: tokenize
/// <summary>
/// Implements the following function
/// node-set tokenize(string, string)
/// </summary>
/// <param name="str"></param>
/// <param name="delimiters"></param>
/// <returns>This function breaks the input string into a sequence of strings,
/// treating any character in the list of delimiters as a separator.
/// The separators themselves are not returned.
/// The tokens are returned as a set of 'token' elements.</returns>
public XPathNodeIterator tokenize(string str, string delimiters)
{
XmlDocument doc = new XmlDocument();
doc.LoadXml("<tokens/>");
if (delimiters == String.Empty)
{
foreach (char c in str)
{
XmlElement elem = doc.CreateElement("token");
elem.InnerText = c.ToString();
doc.DocumentElement.AppendChild(elem);
}
}
else
{
foreach (string token in str.Split(delimiters.ToCharArray()))
{
XmlElement elem = doc.CreateElement("token");
elem.InnerText = token;
doc.DocumentElement.AppendChild(elem);
}
}
return doc.CreateNavigator().Select("//token");
}
示例9: News
/// <summary>
/// Initializes a new instance of the <see cref="News"/> class.
/// </summary>
/// <param name="RssFeedTransformer">The RSS feed transformer.</param>
/// <remarks>Documented by Dev02, 2007-11-28</remarks>
public News(string RssFeedTransformer)
{
XmlDocument rssFeedTransformer = new XmlDocument();
XsltSettings settings = new XsltSettings(false, true); //disable scripts and enable document()
rssFeedTransformer.LoadXml(RssFeedTransformer);
xslTransformer.Load(rssFeedTransformer.CreateNavigator(), settings, new XmlUrlResolver());
}
示例10: GetDataSummary
protected virtual string GetDataSummary(Stream xsltStream)
{
DataSet data = this.GetDataSet;
if (xsltStream == null || data == null)
return null;
Stream dsStream = new MemoryStream();
data.WriteXml(dsStream);
TextWriter tw = new StringWriter();
try
{
XslTransform xsl = new XslTransform();
XmlDocument XSLTDoc = new XmlDocument();
XSLTDoc.Load(xsltStream);
XmlDocument dataDoc = new XmlDocument();
dataDoc.LoadXml(data.GetXml());
XPathNavigator stylesheet = XSLTDoc.CreateNavigator();
xsl.Load(stylesheet, null, null);
XPathNavigator dataNav = dataDoc.CreateNavigator();
xsl.Transform(dataNav, null, tw, null);
}
catch (Exception ex)
{
return null;
}
return tw.ToString();
}
示例11: OpenReader
public override XmlReader OpenReader()
{
// NOTE: Renders in memory. Most objects will already be in memory and therefore small but some implementations might be large.
XmlDocumentFragment frag = new XmlDocument().CreateDocumentFragment();
_obj.WriteXml(frag.CreateNavigator().AppendChild());
return new XmlNodeReader(frag);
}
示例12: ReadXml
public IResourceActions ReadXml(IXPathNavigable idoc)
{
// Basic check on the input
if (idoc == null)
{
Logger.LogError("XmlResourceReader.ReadXml: null XmlDoc input");
throw new ApplicationException(Properties.Resources.COULD_NOT_READ_RESOURCES);
}
XPathNavigator doc = idoc.CreateNavigator();
XPathNavigator rootNode = doc.SelectSingleNode(@"PolicySetResources");
if (rootNode == null)
{
XmlNode node = new XmlDocument().CreateElement("PolicySetResources");
rootNode = node.CreateNavigator();
doc.AppendChild(rootNode);
}
// Check if the document contains an actions node
XPathNavigator actionsNode = rootNode.SelectSingleNode(@"Actions");
if (actionsNode == null)
{
// No actions already defined in the resources so nothing to read
// Return an empty collection of resource actions
return new ResourceActions();
}
return ReadActions(actionsNode);
}
示例13: Apply
// the work of the component
public override void Apply (XmlDocument document, string key) {
// adjust the context
context["key"] = key;
// evaluate the condition
XPathExpression xpath_local = xpath.Clone();
xpath_local.SetContext(context);
Object result = document.CreateNavigator().Evaluate(xpath_local);
// try to intrepret the result as a node set
XPathNodeIterator result_node_iterator = result as XPathNodeIterator;
if (result_node_iterator != null) {
XPathNavigator[] result_nodes = BuildComponentUtilities.ConvertNodeIteratorToArray(result_node_iterator);
//Console.WriteLine("{0} node-set result", result_nodes.Length);
// if it is, apply the child components to each node value
foreach (XPathNavigator result_node in result_nodes) {
// Console.WriteLine(result_node.Value);
ApplyComponents(document, result_node.Value);
}
} else {
//Console.WriteLine("non-node-set result");
// if it isn't, apply the child components to the string value of the result
ApplyComponents(document, result.ToString());
}
}
示例14: BindingRedirectResolverConfigDlg
//=====================================================================
/// <summary>
/// Constructor
/// </summary>
/// <param name="currentProject">The current project</param>
/// <param name="currentConfig">The current XML configuration
/// XML fragment</param>
public BindingRedirectResolverConfigDlg(SandcastleProject currentProject,
string currentConfig)
{
XPathNavigator navigator, root;
InitializeComponent();
project = currentProject;
lnkCodePlexSHFB.Links[0].LinkData = "http://SHFB.CodePlex.com";
items = new BindingRedirectSettingsCollection();
// Load the current settings
config = new XmlDocument();
config.LoadXml(currentConfig);
navigator = config.CreateNavigator();
root = navigator.SelectSingleNode("configuration");
if(!root.IsEmptyElement)
items.FromXml(project, root);
if(items.Count == 0)
pgProps.Enabled = btnDelete.Enabled = false;
else
{
// Binding the collection to the list box caused some
// odd problems with the property grid so we'll add the
// items to the list box directly.
foreach(BindingRedirectSettings brs in items)
lbRedirects.Items.Add(brs);
lbRedirects.SelectedIndex = 0;
}
}
示例15: DiscoverMoveToFollowing
public void DiscoverMoveToFollowing()
{
var doc = new XmlDocument();
doc.LoadXml(@"<root><a id='1'><b>foo</b><c>bar</c></a><a id='2'/></root>");
Assert.That(doc.InnerText.Length, Is.GreaterThan(5));
var nav = doc.CreateNavigator();
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
Assert.That( nav.Name, Is.EqualTo("root") );
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
Assert.That( nav.Name, Is.EqualTo("a") );
Assert.That( nav.GetAttribute("id",""), Is.EqualTo("1") );
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
Assert.That( nav.Name, Is.EqualTo("b") );
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
Assert.That( nav.Name, Is.EqualTo("c") );
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
Assert.That( nav.Name, Is.EqualTo("a") );
Assert.That( nav.GetAttribute("id",""), Is.EqualTo("2") );
Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.False );
}