本文整理汇总了C#中XmlDocument.CreateNavigator方法的典型用法代码示例。如果您正苦于以下问题:C# XmlDocument.CreateNavigator方法的具体用法?C# XmlDocument.CreateNavigator怎么用?C# XmlDocument.CreateNavigator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.CreateNavigator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] arg) {
if (arg.Length < 1) throw new ArgumentException("Must pass one or two command line arguments.");
StringWriter sw = new StringWriter();
string s;
while ((s = Console.ReadLine()) != null) {
sw.WriteLine(s);
}
XmlDocument d = new XmlDocument();
d.LoadXml(sw.ToString());
object ret;
if (arg.Length == 1) {
ret = d.CreateNavigator().Evaluate(arg[0]);
} else if (arg.Length == 2 && arg[0] == "-expr") {
ret = d.CreateNavigator().Evaluate(arg[1]);
} else if (arg.Length == 2 && arg[0] == "-node") {
ret = d.SelectSingleNode(arg[1]);
} else {
throw new ArgumentException("Bad command line arguments.");
}
if (ret is XPathNodeIterator) {
XPathNodeIterator iter = (XPathNodeIterator)ret;
while (iter.MoveNext()) {
Console.WriteLine(iter.Current);
}
} else if (ret is XmlNode) {
Console.WriteLine(((XmlNode)ret).InnerXml);
} else {
Console.WriteLine(ret);
}
}
示例2: saveState
//public void saveState(string deviceName, string[] state, DateTime[] stateDate, int iPacketSize)
//{
// saveState(deviceName, ArraytoString(state, stateDate, iPacketSize) );
//}
public void saveState(string deviceName, string deviceState)
{
if (_sname != String.Empty)
{
try
{
XmlDocument xmlDoc = new XmlDocument();
XPathNavigator xpn = xmlDoc.CreateNavigator();
if (!File.Exists(_fname))
{
CreateXmlDoc(xmlDoc, xpn, deviceName);
}
else
{
xmlDoc.Load(_fname);
}
string xpath = String.Format("/{0}/device[@name='{1}']/currentState", _sname, deviceName);
XPathNavigator currentStateNode = xpn.SelectSingleNode(xpath);
if (currentStateNode == null)
{
AddDeviceToXmlDoc(xmlDoc, xpn, deviceName);
currentStateNode = xpn.SelectSingleNode(xpath);
}
currentStateNode.SetValue(deviceState);
xmlDoc.Save(_fname);
}
catch { }
}
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
//Load document
string booksFile = Server.MapPath("books.xml");
XmlDocument document = new XmlDocument();
document.Load(booksFile);
XPathNavigator nav = document.CreateNavigator();
//Add a namespace prefix that can be used in the XPath expression
XmlNamespaceManager namespaceMgr = new XmlNamespaceManager(nav.NameTable);
namespaceMgr.AddNamespace("b", "http://example.books.com");
//All books whose price is not greater than 10.00
foreach (XPathNavigator node in
nav.Select("//b:book[not(b:price[. > 10.00])]/b:price",
namespaceMgr))
{
Decimal price = (decimal)node.ValueAs(typeof(decimal));
node.SetTypedValue(price * 1.2M);
Response.Write(String.Format("Price raised from {0} to {1}<BR/>",
price,
node.ValueAs(typeof(decimal))));
}
}
示例4: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string xmlFile = Server.MapPath("DvdList.xml");
// Load the XML file in an XmlDocument.
XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
// Create the navigator.
XPathNavigator xnav = doc.CreateNavigator();
XmlText.Text = GetXNavDescr(xnav, 0);
}
示例5: CTypeToManagedType
public static string CTypeToManagedType(string ctype, XmlDocument api_doc)
{
switch (ctype) {
case "GObject":
return "GLib.Object";
case "gchararray":
return "string";
case "gboolean":
return "bool";
case "guint":
return "uint";
case "gint":
return "int";
case "gulong":
case "guint64":
return "ulong";
case "glong":
case "gint64":
return "long";
case "gfloat":
return "float";
case "gdouble":
return "double";
case "GValueArray":
return "GLib.ValueArray";
}
XPathNavigator api_nav = api_doc.CreateNavigator ();
XPathNodeIterator type_iter = api_nav.Select ("/api/namespace/*[@cname='" + ctype + "']");
while (type_iter.MoveNext ()) {
string ret = type_iter.Current.GetAttribute ("name", "");
if (ret != null && ret != String.Empty) {
XPathNavigator parent = type_iter.Current.Clone ();
parent.MoveToParent ();
ret = parent.GetAttribute ("name", "") + "." + ret;
return ret;
}
}
return null;
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string connStr = "database=Northwind;Data Source=.\\SQLEXPRESS;User id=wrox;pwd=wrox1*c";
XmlDocument x = new XmlDocument();
XPathNavigator xpathnav = x.CreateNavigator();
using (SqlConnection conn = new SqlConnection(connStr))
{
conn.Open();
SqlCommand command = new SqlCommand(
"select * from Customers as Customer for XML AUTO, ELEMENTS", conn);
using (XmlWriter xw = xpathnav.PrependChild())
{
xw.WriteStartElement("Customers");
using (XmlReader xr = command.ExecuteXmlReader())
{
xw.WriteNode(xr, true);
}
xw.WriteEndElement();
}
}
Response.ContentType = "text/xml";
x.Save(Response.Output);
}
示例7: getSavedState
public string getSavedState(string deviceName)
{
string retval = string.Empty;
try
{
XmlDocument x = new XmlDocument();
XPathNavigator xpn = x.CreateNavigator();
if (File.Exists(_fname) & (_sname != String.Empty))
{
x.Load(_fname);
string xpath = String.Format("/{0}/device[@name='{1}']/currentState", _sname, deviceName);
XPathNavigator currentStateNode = xpn.SelectSingleNode(xpath);
if (currentStateNode != null)
{
retval = currentStateNode.InnerXml;
}
}
}
catch { }
return retval;
}
示例8: setupUp
public XPathNavigator setupUp(string file)
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
return doc.CreateNavigator();
}
示例9: returnStringWithSetup
public string returnStringWithSetup(string file, string xp)
{
XmlDocument doc = new XmlDocument();
doc.Load(file);
return returnString(doc.CreateNavigator(), xp);
}
示例10: ShowContacts
/// <summary>
/// Show the contacts on the display
/// </summary>
/// <param name="EngageContacts">An </param>
public void ShowContacts(XmlDocument EngageContacts)
{
//Show div that our XML control is in and bind to the control
EngageUserContacts.Visible = true;
Contacts.XPathNavigator = EngageContacts.CreateNavigator();
Contacts.DataBind();
}
示例11: SetSoundbankHeaderFilePath
public static bool SetSoundbankHeaderFilePath(string WwiseProjectPath, string SoundbankPath)
{
try
{
if (WwiseProjectPath.Length == 0)
{
// The setup should not fail if there is no wproj file set. Silently succeed.
return true;
}
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.Load(WwiseProjectPath);
XPathNavigator Navigator = doc.CreateNavigator();
// Navigate to where the header file path is saved. The node has to be there, or else the wproj is invalid.
XPathExpression expression = XPathExpression.Compile("/WwiseDocument/ProjectInfo/Project/PropertyList/Property[@Name='SoundBankHeaderFilePath']");
XPathNavigator node = Navigator.SelectSingleNode(expression);
if (node == null)
{
UnityEngine.Debug.LogError("Could not find SoundBankHeaderFilePath property in Wwise project file. File is invalid.");
return false;
}
// Change the "Value" attribute
if( !node.MoveToAttribute("Value", "") )
{
return false;
}
node.SetValue(SoundbankPath);
doc.Save(WwiseProjectPath);
return true;
}
catch (Exception)
{
// Error happened, return empty string
return false;
}
}
示例12: GetWwiseSoundBankDestinationFolder
public static string GetWwiseSoundBankDestinationFolder(string Platform, string WwiseProjectPath)
{
try
{
if (WwiseProjectPath.Length == 0)
{
return "";
}
XmlDocument doc = new XmlDocument();
doc.Load(WwiseProjectPath);
XPathNavigator Navigator = doc.CreateNavigator();
// Navigate the wproj file (XML format) to where generated soundbank paths are stored
string PathExpression = string.Format("//Property[@Name='SoundBankPaths']/ValueList/Value[@Platform='{0}']", Platform);
XPathExpression expression = XPathExpression.Compile(PathExpression);
XPathNavigator node = Navigator.SelectSingleNode(expression);
string Path = "";
if( node != null )
{
Path = node.Value;
#if !(UNITY_EDITOR_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_METRO)
AkBankPathUtil.ConvertToPosixPath(ref Path);
#endif // #if !(UNITY_EDITOR_WIN || UNITY_XBOX360 || UNITY_XBOXONE || UNITY_METRO)
}
return Path;
}
catch( Exception )
{
// Error happened, return empty string
return "";
}
}
示例13: XmlColladaSchema
public XmlColladaSchema(XmlDocument doc)
{
XPathNavigator navigator = doc.CreateNavigator();
// Move to the first child element of the document. This will be the root element.
//navigator.MoveToChild(XPathNodeType.Element);
navigator.MoveToFirstChild();
string uri = string.Empty;
if (navigator.HasAttributes == true)
{
uri = navigator.NamespaceURI;
}
// Handle asset data
XPathNodeIterator nodesIterator;
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Geometries.root, uri);
if (nodesIterator.MoveNext())
{
_asset = new XmlCollada.Asset(nodesIterator, uri);
}
// Handle geometry library data
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Geometries.root, uri);
if (nodesIterator.MoveNext())
{
_geometries = new XmlCollada.Library_Geometries(nodesIterator, uri);
}
// Handle effects data
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Effects.root, uri);
if (nodesIterator.MoveNext())
{
_effects = new XmlCollada.Library_Effects(nodesIterator, uri);
}
// Handle material data
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Materials.root, uri);
if (nodesIterator.MoveNext())
{
_materials = new XmlCollada.Library_Materials(nodesIterator, uri);
}
// Handle visual scene data
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Visual_Scenes.root, uri);
if (nodesIterator.MoveNext())
{
_visualScenes = new XmlCollada.Library_Visual_Scenes(nodesIterator, uri);
}
// Handle image data
nodesIterator = navigator.SelectChildren(XmlCollada.Library_Images.root, uri);
if (nodesIterator.MoveNext())
{
_images = new XmlCollada.Library_Images(nodesIterator, uri);
}
// Handle the scene
nodesIterator = navigator.SelectChildren(XmlCollada.Scene.root, uri);
if (nodesIterator.MoveNext())
{
_scene = new XmlCollada.Scene(nodesIterator, uri);
}
}
示例14: Serialize
public string Serialize(Account acc, Char chr, int time, string killer, bool firstBorn)
{
__Char = chr;
XmlDocument xmlDoc = new XmlDocument();
{
XmlSerializer serializer = new XmlSerializer(this.GetType()); //makes legends take a few seconds to load
using (var wtr = xmlDoc.CreateNavigator().AppendChild())
serializer.Serialize(wtr, this);
xmlDoc.DocumentElement.Attributes.RemoveAll();
}
XmlElement ac = xmlDoc.CreateElement("Account");
XmlElement name = xmlDoc.CreateElement("Name");
name.InnerText = acc.Name;
ac.AppendChild(name);
xmlDoc.SelectSingleNode("/Fame/Char").AppendChild(ac);
SerializeBonus(xmlDoc, acc, chr, chr.CurrentFame, firstBorn);
XmlElement basFame = xmlDoc.CreateElement("BaseFame");
basFame.InnerText = chr.CurrentFame.ToString();
xmlDoc.DocumentElement.AppendChild(basFame);
XmlElement totalFame = xmlDoc.CreateElement("TotalFame");
totalFame.InnerText = CalculateTotal(acc, chr, chr.CurrentFame, out firstBorn).ToString();
xmlDoc.DocumentElement.AppendChild(totalFame);
XmlElement deathTime = xmlDoc.CreateElement("CreatedOn");
deathTime.InnerText = time.ToString();
xmlDoc.DocumentElement.AppendChild(deathTime);
XmlElement killed = xmlDoc.CreateElement("KilledBy");
killed.InnerText = killer;
xmlDoc.DocumentElement.AppendChild(killed);
StringWriter result = new StringWriter();
xmlDoc.Save(result);
return result.ToString();
}
示例15: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
string username = Convert.ToString(Session["username"]);
Label1.Text = "Welcome" + " " + " " + username;
if (!IsPostBack)
{
// The page is being loaded and accessed for the first time.
// Retrieve user input from the form.
if (Request.QueryString["s"] == null)
// Set the default stock symbol to YHOO.
m_symbol = "YHOO";
else
// Get the user's input.
m_symbol = Request.QueryString["s"].ToString().ToUpper();
// Update the textbox value.
txtSymbol.Value = m_symbol;
// This DIV that contains text and DIVs that displays stock quotes and chart from Yahoo.
// Set the innerHTML property to replaces the existing content of the DIV.
divService.InnerHtml = "<br />";
if (m_symbol.Trim() != "")
{
try
{
// Return the stock quote data in XML format.
String arg = GetQuote(m_symbol.Trim());
if (arg == null)
return;
// Read XML.
// Declare an XmlDocument object to represents an XML document.
XmlDocument xd = new XmlDocument();
// Loads the XML data from a stream.
xd.LoadXml(arg);
// Read XSLT
// Declare an XslCompiledTransform object to transform XML data using an XSLT style sheet.
XslCompiledTransform xslt = new XslCompiledTransform();
// Use the Load method to load the Xsl transform object.
xslt.Load(Server.MapPath("stock.xsl"));
// Transform the XML document into HTML.
StringWriter fs = new StringWriter();
xslt.Transform(xd.CreateNavigator(), null, fs);
string result = fs.ToString();
// Replace the characters ">" and "<" back to "<" and ">".
divService.InnerHtml = "<br />" + result.Replace("<", "<").Replace(">", ">") + "<br />";
// Display stock charts.
String[] symbols = m_symbol.Replace(",", " ").Split(' ');
// Loop through each stock
for (int i = 0; i < symbols.Length; ++i)
{
if (symbols[i].Trim() == "")
continue;
int index = divService.InnerHtml.ToLower().IndexOf(symbols[i].Trim().ToLower() + " is invalid.");
// If index = -1, the stock symbol is valid.
if (index == -1)
{
// Use a random number to defeat cache.
Random random = new Random();
divService.InnerHtml += "<img id='imgChart_" + i.ToString() + "' src='http://ichart.finance.yahoo.com/b?s=" + symbols[i].Trim().ToUpper() + "& " + random.Next() + "' border=0><br />";
// 1 days
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(0," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div1d_" + i.ToString() + "'><b>1d</b></span></a> ";
// 5 days
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(1," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div5d_" + i.ToString() + "'>5d</span></a> ";
// 3 months
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(2," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div3m_" + i.ToString() + "'>3m</span></a> ";
// 6 months
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(3," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div6m_" + i.ToString() + "'>6m</span></a> ";
// 1 yeas
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(4," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div1y_" + i.ToString() + "'>1y</span></a> ";
// 2 years
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(5," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div2y_" + i.ToString() + "'>2y</span></a> ";
// 5 years
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(6," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='div5y_" + i.ToString() + "'>5y</span></a> ";
// Max
divService.InnerHtml += "<a style='font-family: Arial, Helvetica, sans-serif; font-size: 14px; color: Blue;' href='javascript:changeChart(7," + i.ToString() + ", \"" + symbols[i].ToLower() + "\");'><span id='divMax_" + i.ToString() + "'>Max</span></a><br><br /><br /> ";
}
}
}
catch
{
// Handle exceptions
}
}
}
}