开发者

Xml online extract in textbox

I have a xml fil开发者_运维知识库e that is online with the tag <version>1.0</verion> and more, how can I extract the tag version and insert it into a textbox? the xml file is

"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"


You did not provide the xml file. However the answer is simple.

Just use Linq to Xml and parse the file to get the value in version and whatever elements you need.

string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SampleFile><version>1</version><SomeData>Hello World</SomeData></SampleFile>";

XDocument document = XDocument.Parse(xml);

string versionValue = document
    .Descendants("version")
    .Select(i => i.Value.ToString())
    .FirstOrDefault();

Console.WriteLine("The version is {0}", versionValue);

There was a comment which I think meant reading the xml document from a url. You should be able to use the XDocument.Load method.

This will work and pull an xml doc I found from a Google search at this location.

//var document = XDocument.Parse(xml);
var document = XDocument.Load("http://producthelp.sdl.com/SDL%20Trados%20Studio/client_en/sample.xml");


var versionValue = document
    .Descendants("version")
    .Select(i => i.Value.ToString())
    .FirstOrDefault();

Console.WriteLine("The version is {0}", versionValue);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜