1

データセットからxmlファイルを作成しましたが、最初のノードは<NewDataset>それをに変更する必要が<FormData>あり、Platform="Android"やVersion="488"などのパラメーターも追加する必要があります。

データセットのままで変更する方法はありますか、それとも変更後にファイルを呼び出して保存する必要がありますか?

データファイルに関する私の知識は最小限であり、本当に助けが必要です。


現在のxmlファイル

<NewDataSet>
  <FieldData>
    <property_details_gps_location>-29.77861, 31.008617</property_details_gps_location>
    <property_details_address_address1>27 MANJEE</property_details_address_address1>
    <property_details_address_address2>KENVILLE</property_details_address_address2>
    <property_details_address_city>ETHEKWINI</property_details_address_city>
    <property_details_address_state>KWAZULU NATAL</property_details_address_state>
  </FieldData>
</NewDataSet>

私が達成したいこと:

<FormData Platform="Android" PlatformVersion="73" Version="488" DataVersion="1" Description="Investec - Res" FormId="d617a5e8-b49b-4640-9734-bc7a2bf05691" FileId="bce3a788-6725-4ce2-b965-1b55c6e7cc95" EncryptionVerification="" CreatedBy="Shaunm" EditedBy="Shaunm">
  <FieldData>
    <property_details_gps_location>-29.77861, 31.008617</property_details_gps_location>
    <property_details_address_address1>27 MANJEE</property_details_address_address1>
    <property_details_address_address2>KENVILLE</property_details_address_address2>
    <property_details_address_city>ETHEKWINI</property_details_address_city>
    <property_details_address_state>KWAZULU NATAL</property_details_address_state>
  </FieldData>
</FormData>
4

2 に答える 2

3

LINQtoXMLを介して要素/属性を簡単に変更/追加できます。

 XDocument doc = XDocument.Parse(dataSetObject.GetXml());
 doc.Root.Name  = "FormData ";
 doc.Root.Add(new XAttribute("Platform", "Android"));
 ...
 doc.Save("sample.xml");

子ノードを一覧表示するには、

foreach (XElement element in doc.Root.Element("FieldData").Descendants())
 {
   Console.WriteLine(element.Name + " : " + element.Value );
  }
于 2012-09-26T10:16:38.863 に答える
0

XSL-Tを使用して、元のストリームに単純な変換を行うことができます。それを手に入れたら、それを書き込んだり、メモリ内で操作したりできます。

于 2012-09-26T10:01:17.000 に答える