I need to get the full Xml string from an XmlReader (long story). In this sample code though, the final variable, theXmlString, remains empty. Why does it not get assigned the Xml string?
string xmlConfig = @"<pdfMappings>
<pdfFile formTypeEnum=""Int_UT_Additional_Investment_Form_Ind_And_LE_direct"">
<perspective ngiAdminPerspectiveName=""Investor"">
<fieldMapping fieldName=""topmostsubform[0].Page2[0].first_names[0]"" mapTo=""CurrentInvolvedParty.FirstName""></fieldMapping>
<fieldMapping fieldName=""topmostsubform[0].Page2[0].surname[0]"" mapTo=""CurrentInvolvedParty.LastName""></fieldMapping>
</perspective>
</pdfFile>
</pdfMappings>";
var reader = XmlReader.Create(new StringReader(xmlConfig));
string theXmlString = reader.ReadOuterXml();
Just need to start reading first, use
Read()to move to the node thenReadOuterXml()to actually read the value.Alternatively you should also be able to use
reader.MoveToContent();.