2012-03-01 11 views
3

XmlReader(long story)から完全なXml文字列を取得する必要があります。このサンプルコードでは、最後の変数、XmlStringは空のままです。なぜXML文字列が割り当てられないのですか?XmlReaderが空の文字列を返すのはなぜですか?

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

答えて

7

ただ、最初の読み込みを開始し、その後ReadOuterXml()が実際に値を読み取るためにノードに移動するRead()を使用する必要があります。

var reader = XmlReader.Create(new StringReader(xmlConfig)); 
reader.Read(); 
string theXmlString = reader.ReadOuterXml(); 

また、reader.MoveToContent();も使用できるはずです。

+2

そのように簡単です。おかげでrRrRrRr – willem

関連する問題