新NEW了个XmlDocument!
       xmlDoc = new XmlDocument();
       xmlDoc.Load(filePath);
       txtShowBox.Text = xmlDoc.InnerXml;
显示时下面这样子:
<?xml version="1.0"?><ArrayOfBusinessCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><BusinessCode Code="000001" DefaultAssembly="CPC.Service.BatchService.dll" DefaultClass="CPC.Service.BatchService"><SubCodes><SubCode Method="GetUserDailyBusiness" IsSpecail="false" InitBusinessType="Existed" SendToWorkflow="true">01</SubCode></SubCodes><Branches /></BusinessCode></ArrayOfBusinessCode>也就是说没有格式!
怎样才能像一般的XML文档打开的样子的!即有格式的那种!如下:
<?xml version="1.0"?>
<ArrayOfBusinessCode xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <BusinessCode Code="000001" DefaultAssembly="CPC.Service.BatchService.dll" DefaultClass="CPC.Service.BatchService">
    <SubCodes>
      <SubCode Method="GetUserDailyBusiness" IsSpecail="false" InitBusinessType="Existed" SendToWorkflow="true">01</SubCode>
    </SubCodes>
    <Branches />
    <SubCodes>
      <SubCode Method="GetUserDailyBusiness" IsSpecail="false" InitBusinessType="Existed" SendToWorkflow="true">01</SubCode>
    </SubCodes>
  </BusinessCode>
  <BusinessCode Code="000001" DefaultAssembly="CPC.Service.BatchService.dll" DefaultClass="CPC.Service.BatchService">
    <SubCodes>
      <SubCode Method="GetUserDailyBusiness" IsSpecail="false" InitBusinessType="Existed" SendToWorkflow="true">01</SubCode>
    </SubCodes>
    <Branches />
    <SubCodes>
      <SubCode Method="GetUserDailyBusiness" IsSpecail="false" InitBusinessType="Existed" SendToWorkflow="true">01</SubCode>
    </SubCodes>
  </BusinessCode>
</ArrayOfBusinessCode>

解决方案 »

  1.   

    想要格式的话,需要你自己编程 为每个节点 增加 /r/n 或 /tab 
      

  2.   

    C#入门经典上的方法是依据深度每次加2    private void RecurseXmlDocumentNoSiblings(XmlNode root, int indent)
        {
          if (root == null)
            return;      if (root is XmlElement) // Root is an XmlElement type
          {
            listBoxResult.Items.Add(root.Name.PadLeft(root.Name.Length + indent));
            if (root.HasChildNodes)
              RecurseXmlDocument(root.FirstChild, indent + 2);
          }
          else if (root is XmlText)
          {
            string text = ((XmlText)root).Value;
            listBoxResult.Items.Add(text.PadLeft(text.Length + indent));
          }
          else if (root is XmlComment)
          {
            string text = root.Value;
            listBoxResult.Items.Add(text.PadLeft(text.Length + indent));
            if (root.HasChildNodes)
              RecurseXmlDocument(root.FirstChild, indent + 2);
          }
        }
      

  3.   

    具体怎么写代码呢?
    我是直接把xmlDoc.InnerXml 放到TEXTBOX里的!
    我又要怎么判断里面哪里是该换行还是什么的呢?
      

  4.   

     XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(filePath);            System.IO.MemoryStream _Memory =new System.IO.MemoryStream();
                xmlDoc.Save(_Memory);
                txtShowBox.Text = System.Text.Encoding.Default.GetString(_Memory.ToArray
    ());这样?
      

  5.   

    当然不能直接用InnerXml 了,需要 遍历 XML文档的节点 ,在每个 > 后 加\r\n 在 < 前 加\tab 或若干空格
    至于加几个空格 需要判断当前是几级节点 
      

  6.   

    我的要用System.Text.Encoding.UTF8.GetString才不出乱码