如何从XAML过滤文本数据 [英] How to filter text data from xaml

查看:65
本文介绍了如何从XAML过滤文本数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我有一个xaml字符串,

Hi everone,I have a xaml string like this,

<br />
<FlowDocument PagePadding=''5,0,5,0'' AllowDrop=''True'' NumberSubstitution.CultureSource=''User'' <br />
xmlns=''http://schemas.microsoft.com/winfx/2006/xaml/presentation'' <br />
xmlns:s=''clr-namespace:System;assembly=mscorlib''><br />
<Paragraph>I just want<Run xml:lang=''zh-cn''>to</Run><br />
 get <ComboBox IsEditable=''True'' Text=''this'' removed=''#FFF0F8FF'' Name=''cbb_0'' Width=''80'' Height=''23'' IsEnabled=''True'' IsManipulationEnabled=''True''><br />
<s:String>this</s:String><br />
<s:String>that</s:String><br />
</ComboBox> sentence,not <ComboBox IsEditable=''True'' Text=''whole'' removed=''#FFFFFFFF'' Name=''cbb_1'' Width=''80'' Height=''23'' IsEnabled=''True'' IsManipulationEnabled=''True''><br />
<s:String>half</s:String><br />
<s:String>whole</s:String><br />
</ComboBox> file.</Paragraph><br />
</FlowDocument> 



实际上,我只想从这个xaml文件中过滤出用黑色和下划线标记的世界.validate语句是我只想得到这句话,而不是整个文件. 那么,我该如何管理呢? PS,此FlowDocument来自RichTextBox组件.该组件包括其他一些控件,如ComboBox,我需要获取RichTextBox和ComboBox控件的文本. 谢谢.



Actually, I just want to filter this worlds which marked with black and under line tag from this xaml file.The validate sentence is I just want to get this sentence,not whole file. So, how can I manage it? PS,this FlowDocument come from a RichTextBox component.This component includs some other controls like ComboBox,and I need obtain the text of RichTextBox and ComboBox controls''.
Thank you.

推荐答案

我建​​议您看一下正则表达式.那会起作用,但是您必须做一些工作才能做到这一点.也可以创建XmlDocument并扫描节点

I would recommend maybe looking at Regular Expressions. That would work, but you would have to do some work to do that. Can also create and XmlDocument and scan then nodes

   ...
   ...
var text =
       @"<flowdocument pagepadding="5,0,5,0" allowdrop="True" numbersubstitution.culturesource="User">
           xmlns=''http://schemas.microsoft.com/winfx/2006/xaml/presentation''
           xmlns:s=''clr-namespace:System;assembly=mscorlib''>
           <paragraph>I just want<run xml:lang="zh-cn">to</run>
           get <combobox iseditable="True" text="this" removed="#FFF0F8FF" name="cbb_0" width="80" height="23" isenabled="True" ismanipulationenabled="True">
           <s:string xmlns:s="#unknown">this</s:string>
           <s:string xmlns:s="#unknown">that</s:string>
           </combobox> sentence,not <combobox iseditable="True" text="whole" removed="#FFFFFFFF" name="cbb_1" width="80" height="23" isenabled="True" ismanipulationenabled="True">
           <s:string xmlns:s="#unknown">half</s:string>
           <s:string xmlns:s="#unknown">whole</s:string>
           </combobox> file.</paragraph>
           </flowdocument>";

     var doc = new XmlDocument();
     doc.LoadXml(text);
     var sb = new StringBuilder();
     foreach (XmlNode n in doc.ChildNodes)
     {
       ScanNodes(n, sb);
     }
   }

   private void ScanNodes (XmlNode node, StringBuilder sb)
   {
     foreach (XmlNode n in node.ChildNodes)
     {
       //Do building of string here putting in sb
       ScanNodes(n, sb);
     }
   }



必须处理所有特殊情况,但不要太糟



Have to handle all of the special cases, but should not be too bad


这篇关于如何从XAML过滤文本数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆