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 then ReadOuterXml()
to actually read the value.
var reader = XmlReader.Create(new StringReader(xmlConfig));
reader.Read();
string theXmlString = reader.ReadOuterXml();
Alternatively you should also be able to use reader.MoveToContent();
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With