我正在尝试使用SelectNodes,其中属性包含带有撇号的文本
属性为oor:path,节点如下所示:
<item oor:path="/org.openoffice.Office.Histories/Histories/org.openoffice.Office.Histories:HistoryInfo['PickList']/OrderList">
Run Code Online (Sandbox Code Playgroud)
我试过这个代码(并且失败了)......
XmlNodeList xnList = xml.SelectNodes("/oor:items/item[contains(@oor:path, '['PickList']/OrderList')]", nsMgr);
Run Code Online (Sandbox Code Playgroud)
请帮忙!
//安德斯
我正在使用string.Join来显示数组包含的值.当使用字节数组和startIndex并计数时,我偶然发现了一个奇怪的行为.
byte[] byteArr = new byte[]{1,2,3,4,5,6,7,8};
string[] stringArr = new string[] {"1","2","3","4","5","6","7","8"};
Console.WriteLine(string.Format("Whole byteArr: {0}",string.Join(", ", byteArr)));
Console.WriteLine(string.Format("Whole stringArr: {0}",string.Join(", ", stringArr)));
Console.WriteLine(string.Format("0 - 5 byteArr: {0}",string.Join(", ", byteArr,0,5)));
Console.WriteLine(string.Format("0 - 5 stringArr: {0}",string.Join(", ", stringArr,0,5)));
Run Code Online (Sandbox Code Playgroud)
给出了这个结果
整个byteArr:1,2,3,4,5,6,7,8
整个弦Arrr:1,2,3,4,5,6,7,8
0 - 5 byteArr:System.Byte [],0,5
0 - 5 stringArr:1,2,3,4,5
为什么string.Join(",",byteArr,0,5)返回字符串System.Byte [],0,5
我需要使用 HtmlAgilityPack 和 C# 解析此 html 代码。我可以获得 div class="patent_bibdata" 节点,但我不知道如何循环子节点。
在此示例中,有 6 个 href,但我需要将它们分成两组;发明人,分类。我对后两个不感兴趣。该 div 中可以有任意数量的 href。
正如您所看到的,两个组之前有一段文字说明了 href 是什么。
代码片段
HtmlWeb hw = new HtmlWeb();
HtmlDocument doc = m_hw.Load("http://www.google.com/patents/US3748943");
string xpath = "/html/body/table[@id='viewport_table']/tr/td[@id='viewport_td']/div[@class='vertical_module_list_row'][1]/div[@id='overview']/div[@id='overview_v']/table[@id='summarytable']/tr/td/div[@class='patent_bibdata']";
HtmlNode node = m_doc.DocumentNode.SelectSingleNode(xpath);
Run Code Online (Sandbox Code Playgroud)
那么你会怎么做呢?
<div class="patent_bibdata">
<b>Inventors</b>:
<a href="http://www.google.com/search?tbo=p&tbm=pts&hl=en&q=ininventor:%22Ronald+T.+Lashley%22">
Ronald T. Lashley
</a>,
<a href="http://www.google.com/search?tbo=p&tbm=pts&hl=en&q=ininventor:%22Ronald+T.+Lashley%22">
Ronald T. Lashley
</a><br>
<b>Current U.S. Classification</b>:
<a href="http://www.google.com/url?id=3eF8AAAAEBAJ&q=http://www.uspto.gov/web/patents/classification/uspc084/defs084.htm&usg=AFQjCNEZRFtAyKTfNudgc-XVt2-VboD77Q#C084S31200P">84/312.00P</a>;
<a href="http://www.google.com/url?id=3eF8AAAAEBAJ&q=http://www.uspto.gov/web/patents/classification/uspc084/defs084.htm&usg=AFQjCNEZRFtAyKTfNudgc-XVt2-VboD77Q#C084S31200R">84/312.00R</a><br>
<br>
<a href="http://www.google.com/url?id=3eF8AAAAEBAJ&q=http://patft.uspto.gov/netacgi/nph-Parser%3FSect2%3DPTO1%26Sect2%3DHITOFF%26p%3D1%26u%3D/netahtml/PTO/search-bool.html%26r%3D1%26f%3DG%26l%3D50%26d%3DPALL%26RefSrch%3Dyes%26Query%3DPN/3748943&usg=AFQjCNGKUic_9BaMHWdCZtCghtG5SYog-A">
View patent at USPTO</a><br>
<a href="http://www.google.com/url?id=3eF8AAAAEBAJ&q=http://assignments.uspto.gov/assignments/q%3Fdb%3Dpat%26pat%3D3748943&usg=AFQjCNGbD7fvsJjOib3GgdU1gCXKiVjQsw">
Search USPTO Assignment Database
</a><br>
</div>
Run Code Online (Sandbox Code Playgroud)
想要的结果 InventorGroup =
<a …Run Code Online (Sandbox Code Playgroud) 这是我第一次尝试使用 NPOCO,我正在尝试读取 MS SQLEXPRESS 数据库
NPOCO“2.2.49”来自 NuGet、SQLEXPRESS 2008 R2、VS 2013、.NET 4.5
连接字符串是
<connectionStrings>
<add name="TrackTime.Properties.Settings.connectionDB" connectionString="Data Source=ame-PC\SQLEXPRESS;Initial Catalog=TrackTime;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
代码是
db = new Database("TrackTime.Properties.Settings.connectionDB");
var tracks = db.Fetch<trackdatum>();
// List<trackdatum> tracks = db.Fetch<trackdatum>();
trackdatum class
using NPoco;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrackTime
{
[TableName("trackdata")]
[PrimaryKey("trackdata_id")]
[ExplicitColumns]
public partial class trackdatum
{
[Column]
public string trackdata_customer { get; set; }
[Column]
public DateTime trackdata_date { get; set; }
[Column]
public DateTime …Run Code Online (Sandbox Code Playgroud) 我正在阅读其中包含十进制数字的文本文件.它们可以在"任何"文化中制作,因此小数点可能与当前文化不同.
所以我使用正则表达式用当前替换所有不同的CurrencyDecimalSeparators.
我正在使用此代码
string output = Regex.Replace(inValue, @"[\.\?,;/-]", CultureInfo.CurrentCulture.NumberFormat.CurrencyDecimalSeparator);
Run Code Online (Sandbox Code Playgroud)
例如1.25 - > 1,25(我在瑞典)
现在我的问题是:当我第一次尝试这个时,我正在使用这个正则表达式""[\.,;/ - \?]"这不起作用.所有字符都替换为当前分隔符.
例如1.25 - > ,,,,
为什么?
//安德斯
我正在尝试向我的 WPF 程序添加多种语言。所以我使用 Properties.Resources 来存储所有可见的字符串。
在我的 XAML 中我有
<Window x:Class="DCMarker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:loc="clr-namespace:DCMarker.Properties"
Title="{x:Static loc:Resources.Title}" Height="534.6" Width="612" Loaded="Window_Loaded" Closed="Window_Closed"
>
<Grid>
<Menu Height="26" VerticalAlignment="Top">
<MenuItem Header="{x:Static loc:Resources.Tools}">
<MenuItem x:Name="ToolsConnect" Header="{x:Static loc:Resources.ToolsConnect}" Click="ToolsConnect_Click" />
<MenuItem x:Name="ToolsDisconnect" Header="{x:Static loc:Resources.ToolsDisconnect}" Click="ToolsDisconnect_Click" />
<Separator HorizontalAlignment="Left" />
<MenuItem x:Name="ToolsOptions" Header="{x:Static loc:Resources.ToolsOptions}" Click="ToolsOptions_Click" />
</MenuItem>
Run Code Online (Sandbox Code Playgroud)
但是,如果我向 Resources 添加一个字符串,则 XAML 编辑器(或者可能是 Intellisence)将无法识别该字符串。通常,如果我重建解决方案,它们会被识别,但有时我必须重新启动 VS2013。
有人知道为什么以及如何解决这个问题吗?
// 安德斯
我对StreamReader有一个奇怪的问题。我的程序是一个控制台程序,它应该遍历所有* .cs文件的目录结构。然后检查文件中是否有特定单词,并写入文件路径以输出。
using (StringReader sr = new StringReader(fPath))
{
string content = sr.ReadLine(); // sr.ReadToEnd();
Debug.WriteLine(content);
int found = content.IndexOf(p);
if (found != -1)
{
result = true;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我用来在特定文件中查找工作的代码。问题是sr.ReadToEnd(而且还有ReadLine)返回fPath的值而不是文件的内容!
该文件存在且未锁定。
如果fPath是:“ C:\ TEMP \ DC_LV1_LaMine_Mk2Plus_134_ix220_20160404 \ Alarm.Script.cs”
内容将为:“ C:\ TEMP \ DC_LV1_LaMine_Mk2Plus_134_ix220_20160404 \ Alarm.Script.cs”
谁能看到我做错了吗?
c# ×5
c#-4.0 ×2
xpath ×2
.net-4.5 ×1
npoco ×1
regex ×1
sql-server ×1
streamreader ×1
wpf ×1
xaml ×1