Pregunta

I am currently writing a C# script to create an XML file based on a sample I have been given and typically I add an element like so:

node.Add(new XElement("NodeName", new XCData("Value")));

However on the XML sample it uses the following before the CDATA to create a space in the finished document (as transformed in html later):

  // The XML is like:
<NodeName>&#160;&#160;<!CDATA[Value]]></NodeName>

I have tried to add spaces before the value in the XCData declaration but it always ignores them, is there some way I can either add the same as the XML, preserve any spaces I put in or perhaps tab before the value?

¿Fue útil?

Solución

To add a few spaces:

 node.Add(new XElement("NodeName", "  ", new XCData("Value")));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top