从字符串中删除转义序列'\'将其转换为XmlDocument [英] Remove the escape sequence '\' from string to convert it to XmlDocument

查看:118
本文介绍了从字符串中删除转义序列'\'将其转换为XmlDocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web服务返回一个结构对象,所以我得到响应作为以下XML字符串。现在我需要将其加载到XmlDocument对象中,但如何摆脱字符串中的转义序列。 \与每个导致错误。

 <?xml version = \1.0\ encoding = \utf-8\?> 
<引用xmlns:xsi = \http://www.w3.org/2001/XMLSchema-instance\xmlns:xsd = \http://www.w3.org/2001/XMLSchema\xmlns = \http://tempuri.org/\>
< price> 19656< / price> ;
< / Quote>


解决方案

使用 Regex.Unscape 方法。

  String unescapedString = Regex.Unescape(textString); 


I have a web service which returns a struct object, so I get the response as the following XML string. Now I need to load it into XmlDocument object but how do I get rid of the escape sequences in the string. The '\' with every '"' is causing error.

<?xml version=\"1.0\" encoding=\"utf-8\"?>
<Quote xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"http://tempuri.org/\">
<price>19656</price>
</Quote>

解决方案

Use Regex.Unescape method.

String unescapedString = Regex.Unescape(textString);

这篇关于从字符串中删除转义序列'\'将其转换为XmlDocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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