XML document cannot contain multiple root level elements

后端 未结 4 569
萌比男神i
萌比男神i 2021-01-12 13:11

I have a list of codes to which i have an error \"XML document cannot contain multiple root level elements\"


  J         


        
4条回答
  •  说谎
    说谎 (楼主)
    2021-01-12 13:24

    Assuming what you want to do is open the document anyway, you can set the ConformanceLevel of the XmlReader to ConformanceLevel.Fragment.

    XmlReaderSettings settings = new XmlReaderSettings();
    settings.ConformanceLevel = ConformanceLevel.Fragment;
    
    // input is a stream or filename
    using (XmlReader reader = XmlReader.Create(input, settings)) {
        // use the reader
    }
    

提交回复
热议问题