2013-02-12 10 views
0

을 사용하여이 코드를 처리하는 방법을 하나의 공백으로 변환되어있다이XML 공백 문제 내가 코드 문제 아래 사용하여 XML 파일을 생성하고 C#을

using System; 
using System.IO; 
using System.Xml; 

public class Sample 
{ 
    public static void Main() 
    { 
     // Create the writer. 
     XmlTextWriter writer = null; 
     writer = new XmlTextWriter("c:\\ws.html", null); 

     // Write an element (this one is the root). 
     writer.WriteStartElement("p"); 

     // Write the xml:space attribute. 
     writer.WriteAttributeString("xml", "space", null, "preserve"); 

     // Verify that xml:space is set properly. 
     if (writer.XmlSpace == XmlSpace.Preserve) 
      Console.WriteLine("xmlspace is correct!"); 

     // Write out the HTML elements. Insert white space 
     // between 'something' and 'Big' 
     writer.WriteString("something extra spacess in this line but not  coming in xml i want this extra spaces"); 
     writer.WriteWhitespace(" "); 
     writer.WriteElementString("b", "B"); 
     writer.WriteString("ig"); 

     // Write the root end element. 
     writer.WriteEndElement(); 

     // Write the XML to file and close the writer. 
     writer.Close(); 
    } 
} 

답변

0

는 시도 되세요 writer.WriteCData()? 그것은 공백을 보존 할 수있는 <![CDATA[...]]> 블록으로 둘러 쌉니다 (직접 시도하지 않았으므로 말할 수 없습니다).

분명히 데이터 블록으로 사용하지 않으려면 좋지 않습니다.

+0

cdata에 대해 xmlelement로 추가하고 싶습니다. 그러나 작동하지 않지만 유용하지는 않습니다. – Yogesh