C# richTextbox1到textbox1?
我将此文本保存在名为C# richTextbox1到textbox1?,c#,winforms,richtextbox,C#,Winforms,Richtextbox,我将此文本保存在名为richTextBox的富文本框中: <notification_counts> <unseen>0</unseen> </notification_counts> <friend_requests_counts> <unread>1</unread> <unseen>**0**</unseen> </friend_re
richTextBox
的富文本框中:
<notification_counts>
<unseen>0</unseen>
</notification_counts>
<friend_requests_counts>
<unread>1</unread>
<unseen>**0**</unseen>
</friend_requests_counts>
如果富文本框仅包含XML标记,则可以对其进行解析以提取感兴趣的值。例如,使用: 编辑:由于XML标记包含以下内容,因此在选择元素时必须考虑这些内容:
XNamespace fb = "http://api.facebook.com/1.0/";
textBox1.Text = XDocument.Parse(richTextBox.Text).Root
.Element(fb + "friend_requests_counts")
.Element(fb + "unseen").Value;
还有。。。。悬念快把我累死了……你的问题一点也不清楚。你能重新措辞吗?richTextBox 1中有标记(…ecc ecc>at button clic可以提取此标记并插入一个具有值的TextBox 1?@jolly,这是Windows窗体
richTextBox
还是WPF?有趣的是,你确定富文本框中的XML标记有效吗?例如,你问题中的摘录无效(因为有两个根元素)。如果问题不太大,可以用完整的标记更新问题吗?没问题:)这看起来像是XML命名空间问题。请参阅我更新的答案。
using System.Xml.Linq;
textBox1.Text = XElement.Parse(richTextBox.Text)
.Descendant("friend_requests_counts")
.Element("unseen").Value;
XNamespace fb = "http://api.facebook.com/1.0/";
textBox1.Text = XDocument.Parse(richTextBox.Text).Root
.Element(fb + "friend_requests_counts")
.Element(fb + "unseen").Value;