简体   繁体   中英

Get Value from XML

Best way to get the URL from that string?

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.

I would like to add one this is that convert the url to URI after you pull it out from xml. This will make you sure that URL is correct everytime its pulled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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