Read xml file/string in a generic way without knowing the structure

前端 未结 5 1849
终归单人心
终归单人心 2021-01-07 09:00

I want to read a XML hierarchy into a tree of in-memory objects. The XML tree could have n-levels of children. I do not know the exact number. My in-memory objects have a ch

5条回答
  •  一生所求
    2021-01-07 10:06

    Like this?

    using System.Xml ;
    using System.IO;
    class Program
    {
      static void Main( string[] args )
      {
        using ( Stream inputStream = OpenXmlStream() )
        {
          XmlDocument document = new XmlDocument() ;
          document.Load( inputStream ) ;
          Process( document ) ;
        }
      }
      static Stream OpenXmlStream()
      {
        // provide an input stream for the program
      }
      static void Process( XmlDocument document )
      {
        // do something useful here
      }
    }
    

提交回复
热议问题