本文介绍了如何折叠XML字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试解释这个。我需要先保存所有节点< Something> <东西>在一排。结果将是:



I try explain this otherwise. I need to save all nodes in first <Something> <Something> in one row. So result will be:

String s = "Hello to the world"





现在我将此字符串保存到列表中并移至下一个节点:





Now I save this string into a list and move to next node:

string s = "John"





保存到列表和另一个节点:





Save into list and another node:

string s = "January February"





等等

这可能吗?

这个解释更好吗?

抱歉,我的英文和感谢耐心





Etc.
Is this even possible?
Is this explanation better?
Sorry for my english and thanks for patience

<Root>
     <Something>
          <Word>Hello</Word>
          <Word>to</Word>
          <Word>the</Word>
          <Word>World</Word>
     </Something>
     <Something>
          <Word>John</Word>
     </Something>
     <Something>
          <Word>January</Word>
          <Word>February</Word>
     </Something>
</Root>
</pre>

推荐答案



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
namespace ParseXML
{
   class Program
   {
      static void Main(string[] args)
      {

         string strXMl =@"<pre lang='xml'>"
+"<Root>"+
     "<Something>"+
          "<Word>Hello </Word>"
          +"<Word>to </Word>"
          +"<Word>the </Word>"
          +"<Word>World </Word>"
     +"</Something>"
         +"<Something>"
          +"<Word>John</Word>"
     +"</Something>"
     +"<Something>"+
          "<Word>January </Word>"+
          "<Word>February</Word>"
     +"</Something>"+
"</Root>"+
"</pre>";

         XDocument Xele = XDocument.Parse(strXMl);

         foreach (var i in Xele.Descendants("Something"))
         {
            Console.WriteLine(i.Value);

         }

      }
   }
}





您可以使用此方法



You can use this approach


这篇关于如何折叠XML字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-26 23:17
查看更多