Where there is a will , there is a way .
kenly

No pain , no gain .

 

讀寫XML文檔

XML 


<?xml version="1.0" encoding="utf-8" ?>
<Project>
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProductVersion>8.0.50727</ProductVersion>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>{FE735FF0-83C1-409A-8D20-2FAD109B1ECA}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>FIH.GSQM.Learning.Business</RootNamespace>
    <AssemblyName>FIH.GSQM.Learning.Business</AssemblyName>
    <SccProjectName>
    </SccProjectName>
    <SccLocalPath>
    </SccLocalPath>
    <SccAuxPath>
    </SccAuxPath>
    <SccProvider>
    </SccProvider>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Kenly.DBFramework, Version=3.2.1.0, Culture=neutral, PublicKeyToken=579f5f2ea05ed1ec, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>Components\Kenly.DBFramework.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>


        private void GenerateProjectFile(DataSet ds, string path)
        {
            string templateFileName = Application.StartupPath + "\\Template\\Project.csproj";
            if (!File.Exists(templateFileName))
            {
                return;
            }
            string newFileName = path + "\\" + txtNameSpace.Text + ".csproj";

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(templateFileName);
            XPathNavigator navigator = xmlDoc.CreateNavigator();

            XPathNavigator node = navigator.SelectSingleNode("//ProjectGuid");
            node.InnerXml = System.Guid.NewGuid().ToString();

            node = navigator.SelectSingleNode("//RootNamespace");
            node.InnerXml = txtNameSpace.Text;

            node = navigator.SelectSingleNode("//AssemblyName");
            node.InnerXml = txtNameSpace.Text;

            node = navigator.SelectSingleNode("//Project");
            node.AppendChild("<ItemGroup>"+GetCSNodeText(ds)+"</ItemGroup>");
            node.AppendChild("<ItemGroup><Compile Include=\"Utility\\SystemConfig.cs\"/></ItemGroup>");

            node = navigator.SelectSingleNode("//Project");
            node.CreateAttribute("", "xmlns", "", "http://schemas.microsoft.com/developer/msbuild/2003");

            xmlDoc.Save(newFileName);
        }

        private string GetCSNodeText(DataSet ds)
        {
            StringBuilder nodeText = new StringBuilder();

            foreach (DataTable table in ds.Tables)
            {
                nodeText.Append("<Compile Include=\""+table.TableName+".cs\" />");
            }
            return nodeText.ToString();
        }

posted on 2007-06-18 18:01  kenly33  阅读(229)  评论(0编辑  收藏  举报

导航