C# 将标记内部文本设置为null时,是否在XML文件中添加空格?如何将null传递给XML文件或从XML文件中删除子节点?

C# 将标记内部文本设置为null时,是否在XML文件中添加空格?如何将null传递给XML文件或从XML文件中删除子节点?,c#,xml,null,C#,Xml,Null,在我的项目中,我加载一个XML文件,并通过填充内部文本填充其标记。我没有填充所有节点,并保留一些空值 保存XML文件后,设置为null的子节点内部文本将写入5个空格 如何将节点的值设置为null 或者,如何从XML文件中删除子节点 这里是我如何填充节点的内部文本的,我能做的最好是1个空格,但我希望没有空格 目前,我已将所有空值设置为一个空格,我希望它们为空值还是删除它们 XML文件的外观 <?xml version="1.0"?> <FormData Platform="And

在我的项目中,我加载一个XML文件,并通过填充内部文本填充其标记。我没有填充所有节点,并保留一些空值

保存XML文件后,设置为null的子节点内部文本将写入5个空格

如何将节点的值设置为null

或者,如何从XML文件中删除子节点

这里是我如何填充节点的内部文本的,我能做的最好是1个空格,但我希望没有空格

目前,我已将所有空值设置为一个空格,我希望它们为空值还是删除它们

XML文件的外观

<?xml version="1.0"?>
<FormData Platform="Android" PlatformVersion="89" Version="360" DataVersion="1" Description="New Investec - Residential" FormId="9fe48133-ebec-415c-8581-22ba1bfcb237" FileId="d204b364-6b3f-46e0-beed-3f3b2783b8f3" EncryptionVerification="" CreatedBy="Johanc" EditedBy="Johanc" TrackingNum="FormMobi19e9ba3a-2c70-4a5a-a881-44cba4a031c5">
  <FieldData>
    <request_details_lightstone_report Mod="20010101010101" IncludeInPDFExport="Yes"> </request_details_lightstone_report>
    <request_details_export_template Mod="20010101010101" IncludeInPDFExport="Yes"> </request_details_export_template>
    <request_details_reason_for_valuatio Mod="20010101010101" IncludeInPDFExport="Yes"> </request_details_reason_for_valuatio>
    <request_details_valuation_job_numbe Mod="20010101010101" IncludeInPDFExport="Yes"> </request_details_valuation_job_numbe>

    <property_details_gps_location_lat Mod="20010101010101" IncludeInPDFExport="Yes">-29.965495</property_details_gps_location_lat>
    <property_details_gps_location_long Mod="20010101010101" IncludeInPDFExport="Yes">30.838881</property_details_gps_location_long>
    <property_details_address_address1 Mod="20010101010101" IncludeInPDFExport="Yes">8 LETHUBUHLE</property_details_address_address1>
    <property_details_address_address2 Mod="20010101010101" IncludeInPDFExport="Yes">UMLAZI SOUTH</property_details_address_address2>
    <property_details_address_city Mod="20010101010101" IncludeInPDFExport="Yes">ETHEKWINI</property_details_address_city>
    <property_details_address_state Mod="20010101010101" IncludeInPDFExport="Yes">KWAZULU NATAL</property_details_address_state>
    <property_details_address_zip Mod="20010101010101" IncludeInPDFExport="Yes"> </property_details_address_zip>
    <property_details_locality_map Mod="20010101010101" IncludeInPDFExport="Yes">a8267608-6693-40d4-a3e6-d46dfd888037.jpg</property_details_locality_map>
    <property_details_type_of_ownership Mod="20010101010101" IncludeInPDFExport="Yes">Freehold</property_details_type_of_ownership>
    <property_details_text_box Mod="20010101010101" IncludeInPDFExport="Yes"> </property_details_text_box>
    <property_details_text_box_1 Mod="20010101010101" IncludeInPDFExport="Yes"> </property_details_text_box_1>
    <property_details_area_of_site Mod="20010101010101" IncludeInPDFExport="Yes">840</property_details_area_of_site>
    <field_group Mod="20010101010101" IncludeInPDFExport="Yes"> </field_group>
    <property_description_erf_number Mod="20010101010101" IncludeInPDFExport="Yes">532</property_description_erf_number>
    <property_description_portion_number Mod="20010101010101" IncludeInPDFExport="Yes">0</property_description_portion_number>
    <Property_description_township_name Mod="20010101010101" IncludeInPDFExport="Yes">UMLAZI DD</Property_description_township_name>
    <property_description_sectional_titl Mod="20010101010101" IncludeInPDFExport="Yes">
    </property_description_sectional_titl>
    <property_description_section_number Mod="20010101010101" IncludeInPDFExport="Yes"></property_description_section_number>
    <title_deed__municipal_information_text_box Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_box>
    <title_deed__municipal_information_text_box_1 Mod="20010101010101" IncludeInPDFExport="Yes">, ETHEKWINI MUNICIPALITY</title_deed__municipal_information_text_box_1>
    <title_deed__municipal_information_text_box_2 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_box_2>
    <title_deed__municipal_information__2 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information__2>
    <title_deed__municipal_information_text_box_3 Mod="20010101010101" IncludeInPDFExport="Yes">
    </title_deed__municipal_information_text_box_3>
    <title_deed__municipal_information_text_area Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_area>
    <title_deed__municipal_information__1 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information__1>
    <title_deed__municipal_information_text_area_1 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_area_1>
    <title_deed__municipal_information_text_box_4 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_box_4>
    <title_deed__municipal_information_text_area_2 Mod="20010101010101" IncludeInPDFExport="Yes"> </title_deed__municipal_information_text_area_2>
    <main_dwelling_text_box Mod="20010101010101" IncludeInPDFExport="Yes"> </main_dwelling_text_box>
    <main_dwelling_text_box_1 Mod="20010101010101" IncludeInPDFExport="Yes"> </main_dwelling_text_box_1>
    <main_dwelling_text_box_2 Mod="20010101010101" IncludeInPDFExport="Yes"> </main_dwelling_text_box_2>
    <main_dwelling_text_box_3 Mod="20010101010101" IncludeInPDFExport="Yes"> </main_dwelling_text_box_3>
    <valuation_certificate_signature_1 Mod="20010101010101" IncludeInPDFExport="Yes"> </valuation_certificate_signature_1>
    <valuation_certificate_professional_ Mod="20010101010101" IncludeInPDFExport="Yes"> </valuation_certificate_professional_>
  </FieldData>
  <Photos Mod="20010101010101" />
  <VoiceNotes />
  <Drawings Mod="20010101010101" />
  <FieldNotes />
</FormData>

如果值为NULL,请尝试将内部文本设置为string.empty。这只是一个猜测

不要写这行

node.SelectSingleNode(PropInfo[Count].TagName).InnerText = " ";
这不会设置值,但节点将在那里

这应该行得通


Milind

node.RemoveAll;如果节点中包含的唯一内容是InnerText,则将消除多余的空格。

谢谢,我尝试了这个方法,但没有成功,string.empty和在XML文件中创建5个空格。
node.SelectSingleNode(PropInfo[Count].TagName).InnerText = " ";
node.SelectSingleNode(PropInfo[Count].TagName).InnerText = String.Empty;