は、私は次の単純なXMLファイルを持っている:XmlReader.IsEmptyElementが異なる値を返すのはなぜですか?
<?xml version="1.0" encoding="UTF-8" ?><work><pageSetup paperSize="9" fitToHeight="0" orientation="landscape"></pageSetup></work>
私は次のコードを実行すると:
using (XmlReader reader = XmlReader.Create(inFile))
while (reader.Read())
Console.WriteLine("Name = {0}, NodeType = {1}, IsEmptyElement ={2}\n", reader.Name, reader.NodeType, reader.IsEmptyElement);
出力は次のとおりです。
名= XML、ノードタイプ= XMLDECLARATION、IsEmptyElement = False
名前= work、NodeType =要素、IsEmptyElement = False
名=のPageSetup、ノードタイプ=要素、IsEmptyElement = Falseの
名=のPageSetup、ノードタイプ=のendElement、IsEmptyElement = Falseの
名=仕事、ノードタイプ=のendElement、IsEmptyElement = Falseの
あなたが表すPageSetupのIsEmptyElementは= Falseを見ることができるように(私はなぜ知らない... https://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.isemptyelement.aspxを参照)
しかし、私はラインとなり、XML(メモ帳でCtrl + Alt +シフト+ Bを++)foramt場合が壊れる:
<?xml version="1.0" encoding="UTF-8" ?>
<work>
<pageSetup paperSize="9" fitToHeight="0" orientation="landscape"/>
</work>
し、プログラムを実行し、出力は次のようになります。
名= XML、ノードタイプ= XMLDECLARATION、IsEmptyElement = Falseの
名=、ノードタイプ=空白、IsEmptyElement = Falseの
名=仕事、ノードタイプ=要素、I sEmptyElement = Falseの
名=、ノードタイプ=空白、IsEmptyElement = Falseの
名=のPageSetup、ノードタイプ=要素、IsEmptyElement = Trueの
名=、ノードタイプ=空白、IsEmptyElement = Falseの
名=仕事、ノードタイプ=のendElement、IsEmptyElement = Falseの
pageSetupのIsEmptyElement = Trueを参照してください。
なぜ2つのXMLファイルの間に(pageSetupのIsEmptyElementの値で)異なるのですか?
改行のためではありません。これは、あるケースでは、「」と、もう1つは「」です。 – sstan
おそらく前者は空のテキストノードを含んでいますか? –