這裏是我的XML文件...使用XmlReader時,HasValue屬性返回False!爲什麼?
<application>
<name>My Application</name>
<ou/>
<area/>
<created time="na"/>
<id closed="no"/>
<description>My App Description</description>
<version type="beta">1.0</version>
<modified>02/24/2016</modified>
<files>
<file>
<name>my_app.exe</name>
<size type="bytes" complete="yes" updated="no">225684</size>
<description>Main GUI for Application.</description>
<version>1.5</version>
<modified>02/24/2016</modified>
</file>
<file>
<name>testfile.dll</name>
<size type="bytes" complete="yes" updated="no">1024</size>
<description>Support DLL for Application.</description>
<version>1.1</version>
<modified>02/23/2016</modified>
</file>
</files>
</application>
我用它來閱讀我的XML文件...
using (XmlReader reader = XmlReader.Create("my_xml_file.xml"))
{
while (!reader.EOF)
{
switch (reader.NodeType)
{
case XmlNodeType.Element:
if (reader.HasValue)
Debug.WriteLine("Node Value:" + reader.ReadString());
break;
}
}
}
我不知道爲什麼,但出於某種原因,我的reader.HasValue
屬性總是FALSE
。當該節點上有值時,我認爲該屬性應該是TRUE
。如果我只是叫reader.ReadString()
每一次,它會提前讀者擾亂了我想要做的事。我對此有錯嗎?
@ zx485的記錄,沒有拼寫錯誤。 :P看到我不能拯救我的生命我想我會爲我的成就感到自豪,並誇耀它。 ;) –
說得好阿沃。我尊重你的誠實批評。我不得不承認我不是英語母語的人。不過,讓我解釋一下我的主要目標:我不是在這裏譴責你或任何其他人拼寫錯誤或語法錯誤。我只是試圖通過消除單詞的誤導性組合和突出顯示關鍵字來提高其他人的可讀性。這完全符合SO團隊鼓勵的社區標準。提高帖子的可讀性緩解理解,這是對讀者有益的(人誰可以回答的Q值。) – zx485
100%同意!你是否可以用於我的日常語法需求? –