2016-08-04 1 views
0

私はまだXMLファイルで始めています。私はXMLでディレクトリを作成したいと私は、この機能を持っている:XMLをインポートしてディレクトリを作成するC#

runCommand関数は、最初のcomanda_cmd を実行する機能であり、第二の文字列

private void ProcesNode(XmlNode node, string parentPath, string path, string first, string second, string BuiltUnit, string item) 
{ 

    if (!node.HasChildNodes || ((node.ChildNodes.Count == 2) && (node.FirstChild is System.Xml.XmlText))) 
    { 
     //MessageBox.Show(parentPath + "/" + node.Name); 
    } 
    else 
    { 
     foreach (XmlNode child in node.ChildNodes) 
     { 
      comanda_cmd = first + "/" + parentPath + second + "/" + parentPath + "/" + node.Name; 
      string status = RunCommand(comanda_cmd + "/project.pj /n"); 
      //content = "_GEN_PROJECT/" + ProjectName + "/" + BuiltUnit + "/" + item + "/" + parentPath + "/" + node.Name + " already exist"; 
      //MessageBox.Show(content); 
      //check_status(status, content); 
      ProcesNode(child, parentPath + "/" + node.Name, path, first, second, BuiltUnit, item); 
     } 
    } 
} 

されており、私はこのXMLを持っている:

<unit> 
<Unit1> 
    <src> 
     <i> 
      <test1> 
       <test_in1> 
        <test_in_out> 
         <t> 
         </t> 
        </test_in_out> 
       </test_in1> 
      </test1> 
      <test2> 
       <test_in2> 
       </test_in2> 
      </test2> 
     </i> 
    </src> 
    <doc> 
     <i> 
      <test1> 
       <test_in1> 
        <test_in_out> 
         <t> 
         </t> 
        </test_in_out> 
       </test_in1> 
      </test1> 
      <test2> 
       <test_in2> 
       </test_in2> 
      </test2> 
     </i> 
    </doc> 
</Unit1> 
<Unit2> 
    <src> 
     <i> 
     </i> 
    </src> 
</Unit2> 

</unit> 

ProcesNodeを呼び出して、ディレクトリを作成します。例:unit/Unit1/src/i/test1/test_in1/test_in_out 最後のディレクトリ(私の場合は "t")は作成されません。

どこが間違っていますか?なぜそれは最後のディレクトリを作成しないのですか?

+0

最も低いタグ(「」)の場合は、foreachループは入力されません。 'if'条件'(!node.HasChildren || ...) 'が' true'なので、ディレクトリを作成する 'else'ブロックは入力しないでください。 –

+0

あなたは正しいです! 非常にありがとうRene Vogt –

答えて

0

最下位レベルのタグ(<t>タグなど)には子ノードがありません。 !node.HasChildNodesは(おそらく)は、ディレクトリを作成することtrue). So for the tags on the last level you never enter the else`ブロックであるので、あなたのif声明

if (!node.HasChildNodes || ((node.ChildNodes.Count == 2) && (node.FirstChild is System.Xml.XmlText))) 

Thatswhy

は(trueです。

それはあなたが単にその部分(!node.HasChildNodes ||)アウトを残すことができるようです。

関連する問題