在文本框中的Xml在线提取(Xml online extract in textbox)

我有一个xml文件,该文件与<version>1.0</verion>等标签联机,我如何提取标签版本并将其插入到文本框中? xml文件是

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

I have a xml file 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\"?>"

最满意答案

您没有提供xml文件。 但答案很简单。

只需使用Linq到Xml并解析文件以获取版本中的值以及您需要的任何元素。

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);

我认为有一条评论意味着从网址读取xml文档。 你应该能够使用XDocument.Load方法。

这将工作,并拉我在这个位置从谷歌搜索找到的XML文件。

//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);

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);

更多推荐