XML Error: There are multiple root elements

前端 未结 4 1100
悲哀的现实
悲哀的现实 2020-11-27 19:26

I am getting XML from a web service. Here is what the XML looks like:


    
        Text
    

4条回答
  •  情书的邮戳
    2020-11-27 20:11

    You can do it without modifying the XML stream: Tell the XmlReader to not be so picky. Setting the XmlReaderSettings.ConformanceLevel to ConformanceLevel.Fragment will let the parser ignore the fact that there is no root node.

            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            using (XmlReader reader = XmlReader.Create(tr,settings))
            {
                 ...
            }
    

    Now you can parse something like this (which is an real time XML stream, where it is impossible to wrap with a node).

    
      1354902435238
      7073822
    
    
      
      7d1300786a0000000bf9458b0518000000000000000000000000000000000c0c030306001b
    
    
      
      fd1260780912ff3028fea5ffc0387d640fa550f40fbdf7afffe001fff8200fff00f0bf0e000042201421100224ff40312300111400004f000000e0c0fbd1e0000f10e0fccc2ff0000f0fe00f00f0eed00f11e10d010021420401
    
    
      
      fd126078ad11fc4015fefdf5b042ff1010223500000000000000003007ff00f20e0f01000e0000dc0f01000f000000000000004f000000f104ff001000210f000013010000c6da000000680ffa807800200000000d00c0f0
    
    

提交回复
热议问题