如何从xml字符串中获取值 [英] How to get value from xml string
本文介绍了如何从xml字符串中获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友
我需要从XML字符串中找到一个值。因为我的Xml字符串搞砸了,我无法解析。所以我的问题是,无论是借助一些正则表达式还是使用任何其他方式,我都能获得值
例如这是我的
< NUM_AE > 147 < / NUM_AE >
string
i需要获得值147
怎么可能?
提前感谢
解决方案
< blockquote>
string inputString = asjkdfkas djasdasdjasjd<> sfkasdfkaslkfa< NUM_AE> 147< / NUM_AE>< b> sdfsdfsdf< / b> sdfsdfsdfsdf;
正则表达式正则表达式= 新正则表达式( < ; NUM_AE><(*); / NUM_AE>中跨度>);
var regMatch = regex.Match(inputString);
string value = regMatch.Groups [ 1 跨度>]的ToString();
检查 RegEx C#:查找2个已知值之间的字符串 [ ^ ]
查看下面的链接
http:/ /stackoverflow.com/questions/18250671/how-to-read-single-node-value-from-xml-file
Hi Friends
I need to find a value from an XML string. since my Xml string is messed up i am not able to parse. so my question is, whether with help of some regex expression or using any other way can i pick up the value
For example this is my
<NUM_AE>147</NUM_AE>
string
i need to get the value 147
How its possible?
thanks in advance
解决方案
string inputString ="asjkdfkas djasdasdjasjd<>sfkasdfkaslkfa<NUM_AE>147</NUM_AE><b>sdfsdfsdf</b>sdfsdfsdfsdf"; Regex regex = new Regex("<NUM_AE>(.*?)</NUM_AE>"); var regMatch = regex.Match(inputString); string value = regMatch.Groups[1].ToString();
have a look at below link
http://stackoverflow.com/questions/18250671/how-to-read-single-node-value-from-xml-file
这篇关于如何从xml字符串中获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文