0
<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <blog>
    <Title xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Testing this XML File</Title>
    <Name xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Shawn</Name>
    <Image xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Hosting\html\blogimage\</image>
    <Comment xsi:type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Shawn is testing this file</Comment>
  </blog>
</NewDataSet>

データセットの Writexml メソッドを使用しているときに、この xml ファイルの種類を取得し続けるため、XML ファイルを次のようにしたいと考えています。

<NewDataSet>
  <blog>
    <Title>Testing this XML File</Title>
    <Name>Shawn</Name>
    <Image>Hosting\html\blogimage\</image>
    <Comment>Shawn is testing this file</Comment>
  </blog>
</NewDataSet>

この xml は、画像ファイルへのパスを含むブログ用であるため、ブログが読み込まれると、画像が読み込まれます。xml ファイルを読み取るために xml タグを呼び出すときに、命名タグの最初の xml が影響を受けるかどうかを知りたいです。タグ内の w3c リンクを使用して、以前に行ったことのないデータセットからこのように書いている理由を理解する必要があります。

これは、xml が書き込まれる前のコードです: サンプル

public void WriteDataXml(string name, string title, string comment, string path)
    {

      DataSet ds = new DataSet();

     //Sets the data in the hashtable to write new file
     Hashtable lines = new Hashtable();
     lines["Name"] = name;
     lines["Title"] = title;
     lines["Comment"] = comment;
     lines["image"] = path;

     //Convert hash table to data table
     //create an instance of DataTable
     var dataTable = new DataTable(lines.GetType().Name);
     //specify the table name       
     dataTable.TableName = "blog";
     //fill the columns in the DataTable
     foreach (DictionaryEntry entry in lines)
     {
         dataTable.Columns.Add(entry.Key.ToString(), typeof(object));
     }

     //create a new DataRow in the DataTable    
     DataRow dr = dataTable.NewRow();
     //fill the new row in the DataTable
     foreach (DictionaryEntry entry in lines)
     {
         dr[entry.Key.ToString()] = entry.Value.ToString();
     }
     //add the filled up row to the DataTable
     dataTable.Rows.Add(dr);

    //Appending To Existing: Pass values to the dataset to write the xml file from the hash table

     // Add Table to dataset ds
     ds.Tables.Add(dataTable);

    //Reading Existing: Also include current files from the xml in the data set by reading and current

    //Write XML
     string filename = Server.MapPath(@".\blog\") + "comments.xml";
     ds.WriteXml(filename);

    }
4

1 に答える 1