本文整理匯總了C#中Windows.Data.Xml.Dom.XmlDocument.SelectSingleNodeNS方法的典型用法代碼示例。如果您正苦於以下問題:C# XmlDocument.SelectSingleNodeNS方法的具體用法?C# XmlDocument.SelectSingleNodeNS怎麽用?C# XmlDocument.SelectSingleNodeNS使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Windows.Data.Xml.Dom.XmlDocument
的用法示例。
在下文中一共展示了XmlDocument.SelectSingleNodeNS方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: AppxManifest
private AppxManifest()
{
Task t = Task.Run(async () =>
{
Uri u = new Uri("ms-appx:///AppxManifest.xml");
var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(u);
var stream = await file.OpenStreamForReadAsync();
var streamReader = new StreamReader(stream);
var xml = await streamReader.ReadToEndAsync();
XmlDocument xdoc = new XmlDocument();
xdoc.LoadXml(xml);
IXmlNode phoneNode = xdoc.SelectSingleNodeNS("/appx:Package/mp:PhoneIdentity", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:mp=\"http://schemas.microsoft.com/appx/2014/phone/manifest\"");
if (phoneNode != null)
{
IXmlNode phoneIdNode = phoneNode.Attributes.GetNamedItem("PhoneProductId");
if (phoneIdNode != null)
{
PhoneProductId = new Guid(phoneIdNode.InnerText);
}
}
//parse xml
IXmlNode nameNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Properties/appx:DisplayName", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\"");
if (nameNode != null)
{
DisplayName = nameNode.InnerText;
}
IXmlNode publisherNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Properties/appx:PublisherDisplayName", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\"");
if (publisherNode != null)
{
PublisherDisplayName = publisherNode.InnerText;
}
IXmlNode visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/uap:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/manifest/foundation/windows10\" xmlns:uap=\"http://schemas.microsoft.com/appx/manifest/uap/windows10\"");
if (visualElementsNode == null)
{
visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/m3:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:m3=\"http://schemas.microsoft.com/appx/2014/manifest\"");
}
if (visualElementsNode == null)
{
visualElementsNode = xdoc.SelectSingleNodeNS("/appx:Package/appx:Applications/appx:Application/m2:VisualElements", "xmlns:appx=\"http://schemas.microsoft.com/appx/2010/manifest\" xmlns:m2=\"http://schemas.microsoft.com/appx/2013/manifest\"");
}
if (visualElementsNode != null)
{
/*IXmlNode toastCapableNode = visualElementsNode.Attributes.GetNamedItem("ToastCapable");
if (toastCapableNode != null)
{
bool toastCapable = bool.Parse(toastCapableNode.InnerText);
if (toastCapable)
{
Capabilities |= Capability.PushNotification;
}
}*/
IXmlNode bgColorNode = visualElementsNode.Attributes.GetNamedItem("BackgroundColor");
if (bgColorNode != null)
{
string color = bgColorNode.InnerText;
if (color.StartsWith("#"))
{
// hex color
if (color.Length == 7)
{
var r = byte.Parse(color.Substring(1, 2), global::System.Globalization.NumberStyles.HexNumber);
var g = byte.Parse(color.Substring(3, 2), global::System.Globalization.NumberStyles.HexNumber);
var b = byte.Parse(color.Substring(5, 2), global::System.Globalization.NumberStyles.HexNumber);
BackgroundColor = Color.FromArgb(0xff, r, g, b);
}
else if (color.Length == 9)
{
var a = byte.Parse(color.Substring(1, 2), global::System.Globalization.NumberStyles.HexNumber);
var r = byte.Parse(color.Substring(3, 2), global::System.Globalization.NumberStyles.HexNumber);
var g = byte.Parse(color.Substring(5, 2), global::System.Globalization.NumberStyles.HexNumber);
var b = byte.Parse(color.Substring(7, 2), global::System.Globalization.NumberStyles.HexNumber);
BackgroundColor = Color.FromArgb(a, r, g, b);
}
}
else
{
// color name
foreach (PropertyInfo pi in typeof(Colors).GetRuntimeProperties())
{
if (pi.Name.ToLower() == color)
{
BackgroundColor = (Color)pi.GetValue(null);
break;
}
}
}
}
IXmlNode descriptionNode = visualElementsNode.Attributes.GetNamedItem("Description");
if(descriptionNode != null)
{
Description = descriptionNode.InnerText;
}
//.........這裏部分代碼省略.........