Hi
I've got a little problem concerning Rich Text Box (in IP2007), which I want to fill programmatically with XHTML data. I know I need to append XHTML nodes as child nodes of a Rich Text Box, so I'm doing something like this:
if (localNode.MoveToChild("Example", myNamespace))
{
using (XmlWriter rtfWriter = localNode.AppendChild())
{
rtfWriter.WriteStartElement("div", "http://www.w3.org/1999/xhtml");
rtfWriter.WriteString(memberNode.InnerXml);
rtfWriter.WriteEndElement();
rtfWriter.WriteStartElement("div", "http://www.w3.org/1999/xhtml");
rtfWriter.WriteString("linia2");
rtfWriter.WriteEndElement();
rtfWriter.Close();
}
After appending these two div nodes I should be seeing two strings in new lines in the Rich Text Box. Unfortunately this is not happening, I see them inline, without any formatting, like it was just plain text.
I've tried to test aforementioned approach in a new infopath template, and surprisingly everything was fine (button click filled the richtextbox with xhtml) BUT after saving the template and opening it again, it was filling the box with plain text instead of xhtml! After searching a bit I've discovered there's a problem with
namespace of the parent node ('localNode' in this example). The
'myNamespace' in example above is defined as:
string myNamespace = NamespaceManager.LookupNamespace("my");
In the newly created form there wasn't any namespace added to the rich text box node (so it looked like <Example>) but after saving the default "my" namespace was added to the control's node (so it looked like <my:Example xmlns:my=...>) and the xhtml content was rendered as plain text.
I know the namespace nodes are defined upon element's creation and afterwards they are read-only, so what can I do? Any ideas?
Outerxml of my root node is (unneeded parts cut):
<?xml version="1.0"?><?mso-infoPathSolution
name="urn:schemas-microsoft-com:office:infopath:DocView1:-myXSD-2008-10-08T08-15-26"
solutionVersion="1.0.0.307" productVersion="12.0.0" PIVersion="1.0.0.0"
?><?mso-application progid="InfoPath.Document"
versionProgid="InfoPath.Document.2"?>
<my:MainGroup
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-10-08T08:15:26"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"
xml:lang="en-us">
<my:Example></my:Example>