J
James Thurley
I have an XmlDocument object, and need to output the entity from
my code. I potentially need to output other similar entities such as
£ for the GBP sign.
Here is some example code:
//-----------------
XmlDocument doc = new XmlDocument();
XmlElement testElement = doc.CreateElement("test");
doc.AppendChild(testElement);
XmlNode spaceNode = doc.CreateEntityReference("160");
testElement.AppendChild(spaceNode);
StringWriter sw = new StringWriter();
XmlWriter xw = new XmlTextWriter(sw);
doc.WriteContentTo(xw);
//-----------------
So far I have tried:
// Produces " "
doc.CreateTextNode(" ");
// Produces " 
doc.CreateTextNode(" ");
// Exception: "Cannot create an EntityReference node with a name
// starting with '#'."
doc.CreateEntityReference("#160");
// Exception: "There is an invalid name character in 160"
doc.CreateEntityReference("160");
It's frustratingly hard just to put " " into my XML document...
Have I missed something obvious?
Thanks,
James.
my code. I potentially need to output other similar entities such as
£ for the GBP sign.
Here is some example code:
//-----------------
XmlDocument doc = new XmlDocument();
XmlElement testElement = doc.CreateElement("test");
doc.AppendChild(testElement);
XmlNode spaceNode = doc.CreateEntityReference("160");
testElement.AppendChild(spaceNode);
StringWriter sw = new StringWriter();
XmlWriter xw = new XmlTextWriter(sw);
doc.WriteContentTo(xw);
//-----------------
So far I have tried:
// Produces " "
doc.CreateTextNode(" ");
// Produces " 
doc.CreateTextNode(" ");
// Exception: "Cannot create an EntityReference node with a name
// starting with '#'."
doc.CreateEntityReference("#160");
// Exception: "There is an invalid name character in 160"
doc.CreateEntityReference("160");
It's frustratingly hard just to put " " into my XML document...
Have I missed something obvious?
Thanks,
James.