简体   繁体   English

从XML获取价值

[英]Get Value from XML

Best way to get the URL from that string? 从该字符串获取URL的最佳方法?

string text = @"<INMobileCRMConfig>
                    <WebserviceURL>
                       https://179.18.0.30:8200/INPhone/INPhoneMessages/
                    </WebserviceURL>
                </INMobileCRMConfig>";

I tried following: 我尝试了以下操作:

XElement doc = XElement.Parse(text);
string url = doc.FirstNode.ToString();

and

string url = doc.Descendants().Elements("WebserviceURL").Value;

and some other simililar things. 和其他一些类似的东西。

This should work: 这应该工作:

XElement doc = XElement.Parse(text);
var res = doc.Element("WebserviceURL").Value.Trim();

Both are Ok as you are using Naive xmlelement to read the content. 当您使用Naive xmlelement读取内容时,两者都可以。

I would like to add one this is that convert the url to URI after you pull it out from xml. 我想补充一点,就是从xml中拉出URL后将其转换为URI。 This will make you sure that URL is correct everytime its pulled. 这将确保您每次提取URL时都正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM