缺少根元素错误,不好意思求教一下
用XmlDocument.Load()读一个xml文件,代码如下:
//打开xml文件
XmlDocument xmldoc = new XmlDocument ();
xmldoc.Load ( "2007.xml" );
//返回XmlDocument对象
return xmldoc;
xml文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE diary[
<!ELEMENT diary (day*)>
<!ELEMENT day (temp?,weather?,chinaDiary?,japanDiary?,englishDiary?) >
<!ELEMENT temp (#PCDATA)>
<!ELEMENT weather (#PCDATA)>
<!ELEMENT chinaDiary (#PCDATA)>
<!ELEMENT japanDiary (#PCDATA)>
<!ELEMENT englishDiary (#PCDATA)>
<!ATTLIST day date CDATA #REQUIRED>
<!ATTLIST day mood CDATA #IMPLIED>
]>
<diary>
</diary>
------解决方案--------------------路径错了吧,你xml文件放在哪的?
------解决方案--------------------好像这样是不可以的哦~
因为你只有一个根元素的时候,他会认为您没有根元素的
要不,你再加一层试试
<?xml version="1.0" encoding="utf-8" ? >
<!DOCTYPE diary[
<!ELEMENT diary (day*) >
<!ELEMENT day (temp?,weather?,chinaDiary?,japanDiary?,englishDiary?) >
<!ELEMENT temp (#PCDATA) >
<!ELEMENT weather (#PCDATA) >
<!ELEMENT chinaDiary (#PCDATA) >
<!ELEMENT japanDiary (#PCDATA) >
<!ELEMENT englishDiary (#PCDATA) >
<!ATTLIST day date CDATA #REQUIRED >
<!ATTLIST day mood CDATA #IMPLIED >
] >
<diary >
<diaryItem>
</diaryItem>
</diary >