我在浏览XML文档(使用C#)时遇到问题,并获得所有必要的值.我成功浏览了XML文档中所有指定的XmlNodeLists,成功获取了所有XmlNode值,但我必须在此XmlNodeList之外获取一些值.
例如:
<?xml version="1.0" encoding="UTF-8" ?>
<Element xsi:schemaLocation="http://localhost/AML/CaseInvestigationMangement/Moduli/XmlImportControls/xsdBorrow.xsd xsd2009027_kor21.xsd" Kod="370" xmlns="http://localhost/AML/CaseInvestigationMangement/Moduli/XmlImportControls/xsdBorrow.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
/2001/XMLSchema-instance">
<ANode>
<BNode>
<CNode>
<Example>
<Name>John</Name>
<NO>001</NO>
</Example>
</CNode>
</BNode>
<ID>1234</ID>
<Date>2011-10-01</Date>
</ANode>
<ANode>
<BNode>
<CNode>
<Example>
<Name>Mike</Name>
<NO>002</NO>
</Example>
</CNode>
</BNode>
<ID>5678</ID>
<Date>2011-03-31</Date>
</ANode>
</Element>
Run Code Online (Sandbox Code Playgroud)
这是获取XML文档中每个找到的ANode中节点Name和NO的值的代码:
XmlDocument xml = new XmlDocument();
xml.LoadXml(myXmlString); //myXmlString is the xml file in string //copying xml to string: string myXmlString = xmldoc.OuterXml.ToString();
XmlNodeList xnList = xml.SelectNodes("/Element[@*]/ANode/BNode/CNode");
foreach (XmlNode xn in xnList)
{
XmlNode example = xn.SelectSingleNode("Example");
if (example != null)
{
string …Run Code Online (Sandbox Code Playgroud) 我们使用从文件路径安装的ClickOnce部署我们的应用程序.对于24个版本,它一直运行良好 - 现在,在版本25上,一旦应用程序安装并启动它,我会收到以下错误:
替代文字http://i49.tinypic.com/zk4krl.png
如果我在同一台机器上测试以前的部署,它就可以工作.
我哪里可以开始寻找找出此错误的原因?我已经检查了Windows事件日志 - 什么都没有.
编辑:我注意到在显示对话框时,我的临时文件夹中生成了一个临时的xml文件'WER561D.tmp.WERInternalMetadata.xml'.这是内容(它可能包含有助于那些比我更有知识的人的线索):
<?xml version="1.0" encoding="UTF-16"?>
<WERReportMetadata>
<OSVersionInformation>
<WindowsNTVersion>6.1</WindowsNTVersion>
<Build>7600 </Build>
<Product>(0x4): Windows 7 Enterprise</Product>
<Edition>Enterprise</Edition>
<BuildString>7600.16385.x86fre.win7_rtm.090713-1255</BuildString>
<Revision>1</Revision>
<Flavor>Multiprocessor Free</Flavor>
<Architecture>X86</Architecture>
<LCID>1033</LCID>
</OSVersionInformation>
<ProblemSignatures>
<EventType>CLR20r3</EventType>
<Parameter0>applaunch.exe</Parameter0>
<Parameter1>2.0.50727.4927</Parameter1>
<Parameter2>4a275abe</Parameter2>
<Parameter3>mscorlib</Parameter3>
<Parameter4>2.0.0.0</Parameter4>
<Parameter5>4a275af7</Parameter5>
<Parameter6>4f3</Parameter6>
<Parameter7>0</Parameter7>
<Parameter8>System.Security.Security</Parameter8>
</ProblemSignatures>
<DynamicSignatures>
<Parameter1>6.1.7600.2.0.0.256.4</Parameter1>
<Parameter2>1033</Parameter2>
</DynamicSignatures>
<SystemInformation>
-- removed for privacy reasons --
</SystemInformation>
</WERReportMetadata>
Run Code Online (Sandbox Code Playgroud)
另一个关键点是我通过Visual Studio发布,没有手动清单编辑.
我的应用程序中嵌入了Windows窗体WebBrowser控件.有没有办法使用WebBrowser或HtmlDocument API获取网页图标?即使从本地文件系统获取它也足够了.将图标作为单独的操作下载将是最后的手段......
谢谢.
选择以下房产:
public string Foo
{
get;
private set;
}
Run Code Online (Sandbox Code Playgroud)
使用反射,我仍然可以在拥有类之外设置此属性的值.有办法防止这种情况吗?删除set访问器不是一个选项,因为它必须是WCF友好的.
我有一个方法,它实质上将数据表转换为我称之为"包"的对象列表.每个会话多次调用此代码,许多会话同时运行,有时会有数千行.因此,我需要尽可能快.我有一个xml文件,其中包含DataColumn到Property映射.优化的主要方法是ConvertRowToBag- 传入的类型参数是派生自的类型BagBase.
这是一个很长的代码,但任何提示将非常感激.
public class BagBase
{
/// <summary>
/// Dictionary of properties and names
/// </summary>
private static Dictionary<string, PropertyInfo> propertyDictionary = new Dictionary<string, PropertyInfo>();
/// <summary>
/// Table of column/property mappings
/// </summary>
private static DataTable mappings = new DataTable("Mappings");
/// <summary>
/// Returns true if the map exists
/// </summary>
/// <param name="columnName"></param>
/// <param name="type"></param>
/// <returns></returns>
private static bool MappingExists(string columnName, Type type)
{
DataRow [] rows = BagBase.mappings.Select(String.Format("Type = '{0}' …Run Code Online (Sandbox Code Playgroud) 我有一个具有可配置延迟(Timespan)的工具,我想根据值设置标签的文本.这是我的代码:
StringBuilder time = new StringBuilder();
if (Settings.Default.WaitPeriod.Hours > 0)
{
time.AppendFormat("{0} hour(s)", Settings.Default.WaitPeriod.Hours);
}
if (Settings.Default.WaitPeriod.Minutes > 0)
{
time.AppendFormat("{0}{1} minute(s)", time.Length > 0 ? " and " : "", Settings.Default.WaitPeriod.Minutes);
}
if (Settings.Default.WaitPeriod.Seconds > 0)
{
time.AppendFormat("{0}{1} second(s)", time.Length > 0 ? " and " : "", Settings.Default.WaitPeriod.Seconds);
}
this.questionLabel.Text = String.Format("What have you been doing for the past {0}?", time);
Run Code Online (Sandbox Code Playgroud)
我发现"(s)"特别令人恼火 - 但不要想要一百万if/ternary if语句.
因此,忽略非本地化字符串,您能想到更好的方法吗?
c# ×5
.net ×2
reflection ×2
winforms ×2
clickonce ×1
datatable ×1
favicon ×1
install ×1
launch ×1
properties ×1
readonly ×1
string ×1
xml ×1
xmldocument ×1