本文整理匯總了C#中System.Xml.XmlDataDocument.CreateNavigator方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDataDocument.CreateNavigator方法的具體用法?C# XmlDataDocument.CreateNavigator怎麽用?C# XmlDataDocument.CreateNavigator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Xml.XmlDataDocument
的用法示例。
在下文中一共展示了XmlDataDocument.CreateNavigator方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetDataSet
/// <summary>
/// Generates an XPath navigatable dataset based on sql
/// </summary>
/// <param name="sql">The SQL to execute</param>
/// <param name="setName">Name of the returned set</param>
/// <returns>A <setName></setName> element with the results, or an <error></error> element if an exception occured</returns>
public static XPathNodeIterator GetDataSet(string sql, string setName)
{
try
{
DataSet ds = GetDataSetFromSql(sql, setName);
var dataDoc = new XmlDataDocument(ds);
return dataDoc.CreateNavigator().Select(".");
}
catch (Exception e)
{
// If there's an exception we'll output an error element instead
var errorDoc = new XmlDocument();
errorDoc.LoadXml(String.Format("<error>{0}</error>", HttpUtility.HtmlEncode(e.ToString())));
return errorDoc.CreateNavigator().Select(".");
}
}
示例2: Navigator
public void Navigator()
{
XmlDataDocument doc = new XmlDataDocument();
doc.DataSet.ReadXmlSchema(new StringReader(RegionXsd));
doc.Load(new StringReader(RegionXml));
XPathNavigator Nav = doc.CreateNavigator();
Nav.MoveToRoot();
Nav.MoveToFirstChild();
Assert.Equal("Root", Nav.Name.ToString());
Assert.Equal(string.Empty, Nav.NamespaceURI.ToString());
Assert.Equal("False", Nav.IsEmptyElement.ToString());
Assert.Equal("Element", Nav.NodeType.ToString());
Assert.Equal(string.Empty, Nav.Prefix);
Nav.MoveToFirstChild();
Nav.MoveToNext();
Assert.Equal("Region", Nav.Name.ToString());
Assert.Equal("2Western", Nav.Value.Substring(0, Nav.Value.IndexOfAny(new[] { '\r', '\n' })));
Nav.MoveToFirstChild();
Assert.Equal("2", Nav.Value);
Nav.MoveToRoot();
Assert.Equal("Root", Nav.NodeType.ToString());
}
示例3: Navigator
public void Navigator ()
{
XmlDataDocument doc = new XmlDataDocument ();
doc.DataSet.ReadXmlSchema ("Test/System.Xml/region.xsd");
doc.Load ("Test/System.Xml/region.xml");
XPathNavigator Nav = doc.CreateNavigator ();
Nav.MoveToRoot ();
Nav.MoveToFirstChild ();
Assert.AreEqual ("Root", Nav.Name.ToString (), "test#01");
Assert.AreEqual (string.Empty, Nav.NamespaceURI.ToString (), "test#02");
Assert.AreEqual ("False", Nav.IsEmptyElement.ToString (), "test#03");
Assert.AreEqual ("Element", Nav.NodeType.ToString (), "test#04");
Assert.AreEqual (string.Empty, Nav.Prefix, "test#05");
Nav.MoveToFirstChild ();
Nav.MoveToNext ();
Assert.AreEqual ("Region", Nav.Name.ToString (), "test#06");
Assert.AreEqual ("2Western", Nav.Value.Substring(0, Nav.Value.IndexOf ("\n") - 1), "test#07");
Nav.MoveToFirstChild ();
Assert.AreEqual ("2", Nav.Value, "test#08");
Nav.MoveToRoot ();
Assert.AreEqual ("Root", Nav.NodeType.ToString (), "test#09");
}
示例4: LogErrorEventlog
private static void LogErrorEventlog(XmlDataDocument _XmlDataDocument)
{
if (!EventLog.SourceExists("NetVerk.fo"))
{
EventLog.CreateEventSource("NetVerk.fo", "Application");
}
EventLog myLog = new EventLog();
myLog.Source = "NetVerk.fo";
string _ErrorString = "Error:";
XPathNavigator navigator = _XmlDataDocument.CreateNavigator();
navigator.MoveToFirst();
navigator.MoveToFirstChild();
navigator.MoveToFirstChild();
navigator.MoveToFirstChild();
//Format :
//Application name, Desription
for (int i = 0; i < 2; i++)
{
_ErrorString += navigator.LocalName + " - ";
navigator.MoveToFirstChild();
_ErrorString += navigator.Value + " ";
navigator.MoveToParent();
navigator.MoveToNext();
}
myLog.WriteEntry(_ErrorString);
}
示例5: LogErrorFile
private static void LogErrorFile(XmlDataDocument _XmlDataDocument)
{
CheckDirectory(InnerXmlFileName);
_innerXmlTextFileMutex.WaitOne();
FileInfo _LogFile = new FileInfo(InnerXmlFileName);
StreamWriter _SW;
if (!_LogFile.Exists)
{
_SW = _LogFile.CreateText();
}
else
{
_SW = _LogFile.AppendText();
}
_SW.WriteLine("<Log>");
_SW.WriteLine("\t<Category>");
_SW.WriteLine("\tError");
_SW.WriteLine("\t</Category>");
_SW.WriteLine("\t<DateTime>");
_SW.WriteLine("\t" + DateTime.Now.ToString());
_SW.WriteLine("\t</DateTime>");
_SW.WriteLine("\t<Message>");
XPathNavigator navigator = _XmlDataDocument.CreateNavigator();
navigator.MoveToFirst();
navigator.MoveToFirstChild();
navigator.MoveToFirstChild();
navigator.MoveToFirstChild();
//Format :
//Application name
//Desription
//Details
//LineNumber
//SourceLine
for (int i = 0; i < 5; i++)
{
_SW.WriteLine("\t\t<" + navigator.LocalName + ">");
navigator.MoveToFirstChild();
_SW.WriteLine("\t\t" + navigator.Value);
navigator.MoveToParent();
_SW.WriteLine("\t\t</" + navigator.LocalName + ">");
navigator.MoveToNext();
}
_SW.WriteLine("\t</Message>");
_SW.WriteLine("</Log>");
_SW.Flush();
_SW.Close();
_innerXmlTextFileMutex.ReleaseMutex();
}
示例6: LogErrorHtml
private static void LogErrorHtml(XmlDataDocument _XmlDataDocument)
{
_HtmlFileMutex.WaitOne();
XslTransform _XslTransform = new XslTransform();
_XslTransform.Load(AppDomain.CurrentDomain.BaseDirectory + "/Log/ReportTemplate.xslt");
XPathNavigator _Navigator = _XmlDataDocument.CreateNavigator();
string m_LogName = InnerXmlFileName.Replace(".txt", DateTime.Now.Ticks.ToString()) + ".html";
CheckDirectory(m_LogName);
StreamWriter _SW = new StreamWriter(m_LogName);
_XslTransform.Transform(_Navigator, null, _SW, null);
_SW.Flush();
_SW.Close();
_HtmlFileMutex.ReleaseMutex();
}
示例7: Button1_Click
protected void Button1_Click(object sender, EventArgs e)
{
string index = @"C:\Users\Soumya\Documents\Visual Studio 2013\WebSites\WebSite1\indx";
Directory dir = FSDirectory.GetDirectory(index);
System.Xml.XmlDataDocument file = new System.Xml.XmlDataDocument();
file.Load(@"C:\Users\Soumya\Documents\Visual Studio 2013\WebSites\WebSite1\App_Data\movies.xml");
Analyzer ana = new StandardAnalyzer();
IndexWriter wr = new IndexWriter(dir, ana, true);
try
{
foreach (System.Xml.XPath.XPathNavigator movie in file.CreateNavigator().Select("//movie"))
{
string b = "", c = "", d = "", e2 = "", f = "", g = "", h = "", i = "", j = "", k = "", l = "", m = "", n = "", o = "", p = "";
Document movieIterator = new Document();
movieIterator.Add(new Field("id", movie.GetAttribute("id", string.Empty), Field.Store.YES, Field.Index.NO, Field.TermVector.NO));
int a = Convert.ToInt32(movie.GetAttribute("id", string.Empty));
if (movie.SelectSingleNode("imageLink") != null)
{
b = movie.SelectSingleNode("imageLink").Value;
}
if (movie.SelectSingleNode("name") != null)
{
c = movie.SelectSingleNode("name").Value;
movieIterator.Add(new Field("name", movie.SelectSingleNode("name").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("score") != null)
{
d = movie.SelectSingleNode("score").Value;
}
if (movie.SelectSingleNode("MovieInfo") != null)
{
e2 = movie.SelectSingleNode("MovieInfo").Value;
movieIterator.Add(new Field("MovieInfo", movie.SelectSingleNode("MovieInfo").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("duration") != null)
{
f = movie.SelectSingleNode("duration").Value;
}
if (movie.SelectSingleNode("genres") != null)
{
XPathNodeIterator xx = movie.SelectSingleNode("genres").SelectChildren(XPathNodeType.Element);
while (xx.MoveNext())
{
g = g + xx.Current.Value + "***";
}
movieIterator.Add(new Field("genres", movie.SelectSingleNode("genres").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("director") != null)
{
h = movie.SelectSingleNode("director").Value;
movieIterator.Add(new Field("director", movie.SelectSingleNode("director").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("writer") != null)
{
i = movie.SelectSingleNode("writer").Value;
movieIterator.Add(new Field("writer", movie.SelectSingleNode("writer").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("TheatreRelease") != null)
{
j = movie.SelectSingleNode("TheatreRelease").Value;
}
if (movie.SelectSingleNode("DvdRelease") != null)
{
k = movie.SelectSingleNode("DvdRelease").Value;
}
if (movie.SelectSingleNode("BOCollection") != null)
{
l = movie.SelectSingleNode("BOCollection").Value;
}
if (movie.SelectSingleNode("Production") != null)
{
m = movie.SelectSingleNode("Production").Value;
movieIterator.Add(new Field("Production", movie.SelectSingleNode("Production").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("actors") != null)
{
XPathNodeIterator xx = movie.SelectSingleNode("actors").SelectChildren(XPathNodeType.Element);
while (xx.MoveNext())
{
n = n + xx.Current.Value + "***";
}
movieIterator.Add(new Field("actors", movie.SelectSingleNode("actors").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("reviews") != null)
{
XPathNodeIterator xx = movie.SelectSingleNode("reviews").SelectChildren(XPathNodeType.Element);
while (xx.MoveNext())
{
o = o + xx.Current.Value + "***";
}
movieIterator.Add(new Field("reviews", movie.SelectSingleNode("reviews").Value, Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
}
if (movie.SelectSingleNode("classifiedscore") != null)
{
k = movie.SelectSingleNode("classifiedscore").Value;
}
SqlConnection con = new SqlConnection(connStr);
//.........這裏部分代碼省略.........