4

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();

1 Answer 1

9

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();.

1
  • 3
    As simple as that. Thanks rRrRrRr
    – willem
    Mar 1, 2012 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.