tags:

views:

38

answers:

3

I am trying to write a string out to an xml node

strConverted = strConverted + "<sup>" + Mid(strConvertMe, intC, 1) + "</sup>"

Doc = New XmlDocument()
Me.Root.AppendChild(h.BuildXML())

produces XML like this (in part):
String that was converted <sup>2</sup> more string stuff

see how the & in the string gets turned into &amp

anyone have any ideas how to stop this?

+1  A: 

If the & is part of a string, it should be converted into &. That's part of XML escaping.

What are you actually trying to represent?

It would also help if you could provide more useful sample code - currently you've got three statements which aren't directly linked at all, using a completely different set of variables each time.

I strongly suspect that you shouldn't be building up your strConverted as a string in the first place - any XML generation code which contains "manual" tags is begging to be rewritten to use the API more idiomatically.

If you can give us more indication of what you're trying to achieve, we're more likely to be able to help you.

Jon Skeet
Trying to embed <sup></sup> in the XML so that that content will be superscripted. <sup>2</sup# renders the number 2 properly as superscript. There is some code to create an XML document object and assign strConverted to one of its nodes. Works correctly 99.9% of the time. When I try to write an it is converted to sup/sup renders as <sup>2</sup> on the page
The previous comment got all messed up
<sup>2</sup# renders the number 2 properly as superscriptsup/sup renders as <sup>2</sup> on the page
There is some code to create an XML document object and assign strConverted to one of its nodes. It works correctly 99.9% of the time. When I try to write an
I think you're confused about the difference between text nodes and elements. If you want to nest one element within another, you should do so using the API. If you want to embed a text string within the XML, just do that instead - and let the escaping happen. When you read back the text later, it will be unescaped again.
Jon Skeet
A: 

Keep your string from getting parsed using the CData directive:

XmlDocument doc = new XmlDocument();
doc.LoadXml("<converted>" +
            "<![CDATA[" +
             strConverted +
            "]]>" +
            "</converted>");
Andrew Cowenhoven
I though of that but for some reason my boss doesn't want me to do that. :wtf
A: 

If you're trying to add a sup element to your XML output, just create a sup element:

XmlElement sup = doc.CreateElement("sup");
sup.InnerText = value;
doc.DocumentElement.AppendChild(sup);
Robert Rossney