2014-11-28 2 views
-3

아래의 imput xml에서 설명한대로 출력 xml을 가져와야합니다.xml 노드에서 공백을 제거하여 속성 값이 아님

입력 XML

<BPSResponse> <Response>  <Code>804</Code>  <Text>TagID value is not genuine.</Text> </Response> </BPSResponse> 

XML 출력

<BPSResponse><Response><Code>804</Code><Text>TagID value is not genuine.</Text></Response></BPSResponse> 

내가 XElement를하여 XML을 생성하고있다.

var bpsResponseXml = new XElement("BPSResponse"); 

      for (int i = 0; i < bpsResponseStatusCodes.Count; i++) 
      { 
       var bpsResponse = BPSResponseDictionary.GetBPSResponse(bpsResponseStatusCodes[i]); 

       bpsResponseXml.Add(new XElement("Response", 
            new XElement("Code", bpsResponse.Code), 
            new XElement("Text", bpsResponse.Text))); 
      } 

      var outPutXml = bpsResponseXml.Value; 

출력 XML을 위의 형식으로 원합니다.

답변

0

다음은 문제를 해결할 샘플 코드입니다.

var bpsResponseXml = new XElement("BPSResponse");   

bpsResponseXml.Add(new XElement("Response", 
            new XElement("Code", "804"), 
            new XElement("Text", "TagID value is not genuine"))); 

var outPutXml = bpsResponseXml.ToString(System.Xml.Linq.SaveOptions.DisableFormatting); 
1
var doc = new System.Xml.XmlDocument() 
{ 
    PreserveWhitespace = false 
}; 
doc.LoadXml(xmlString); 
string flat = doc.OuterXml; 
관련 문제