该文档已经有一个'documentelement'节点。 [英] this document already has a 'documentelement' node.

查看:332
本文介绍了该文档已经有一个'documentelement'节点。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XmlReader reader = cmd.ExecuteXmlReader();

con.Close();

XmlDocument doc = new XmlDocument();

doc.Load(读者); //在这一行我得到错误



和我的xmlfile是



 <   ID   >  76 <   / ID  > ;  
< 名称 > ushaChaitu < /姓名 > ;
< 城市 > 2 < / City >
< EmailID > UshaChaitu@Kp.com < / EmailID >





没有根元素那么为什么我在加载这个xmlfile

解决方案

时会出现这个错误你需要让root不是一个有效的XML文档。请执行以下操作



  string  xmlContent = File.ReadAllText(  yourxmlFilePath.xml); 
XDocument x = XDocument.Parse( < root> + xml + < / root>);


< blockquote>看起来您的xml文件格式不正确,如

 <?  xml     version   = < span class =code-keyword> 1.0    encoding   =  utf-8  >  

标题。



另请参阅以下链接:

此-文档已经具有-A-DocumentElement

XmlReader reader = cmd.ExecuteXmlReader();
con.Close();
XmlDocument doc = new XmlDocument();
doc.Load(reader);//at this line im getting error

and my xmlfile is

<ID>76</ID>
<Name>ushaChaitu</Name>
<City>2</City>
<EmailID>UshaChaitu@Kp.com</EmailID>



there is no root element then why im getting this error when im loading this xmlfile

解决方案

you need to have a root not to be a valid XML Document. Do as below

string xmlContent = File.ReadAllText("yourxmlFilePath.xml");
XDocument x= XDocument.Parse("<root>"+xml+"</root>");


Seems your xml file is not well formed like where is the

<?xml version="1.0" encoding="utf-8"?> 

header.

Also refer the below link:
This-document-already-has-a-DocumentElement


这篇关于该文档已经有一个'documentelement'节点。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆