Nope no database. I have code behind in c#. I created a test form that just
has a Rich TextBox a and b. And when the user submits the form I would like
to transfer the Rich Text from A to B and beable to keep the line breaks.
I've tried to do something like this
Node =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").cloneNode(False)
thisXDocument.DOM.selectSingleNode("/my:myFields/my:b").appendChild(Node)
I do understand why that won't work but I'm still new to XML.
and If I do this ...
thisXDocument.DOM.selectSingleNode("/my:myFields/my:b").text =
thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").text
Then it copies the text over without keeping the line breaks.
Thanks for any help!
- Andrew
If your RTF-a contains line breaks and you put a breakpoint on e.g.
string RTF-a = thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").xml;
you will see a bunch of <DIV> elements contained in <my:a>. What worked for
me was to build a loop over the childNodes contained in <my:a> and then
compose a string from these childNodes. I haven't yet found a "nicer" way to
copy the XML inside a node. You can do a check on
thisXDocument.DOM.selectSingleNode("/my:myFields/my:a").hasChildNodes()
before starting the loop over the childNodes. Then you must retrieve the
nodeName, nodeType, and namespaceURI of <my:b> (these are all properties of a
node) and use them to create the new XML for this node as a string that
contains the inner XML copied from <my:a>.
You can then use thisXDocument.CreateDOM() to instantiate a new XML node
(we'll call this newChild), and then newChild.loadXML() to load the XML
string for the new <my:b> into this new XML node.
Then you retrieve the old <my:b> (let's call it oldChild) and with a
replaceChild(), you replace it with the new XML node for <my:b> like this
oldChild.parentNode.replaceChild(newChild.documentElement, oldChild);
Hope this helps. If you're still having difficulty getting this to work,
I'll convert your scenario to a "recipe" (=solution) and post it on my
website this weekend.
---
S.Y.M. Wong-A-Ton
> Nope no database. I have code behind in c#. I created a test form that just
> has a Rich TextBox a and b. And when the user submits the form I would like
[quoted text clipped - 41 lines]
> > > > > Thanks,
> > > > > Andrew
Andrew - 09 Mar 2006 14:15 GMT
Thank you for all of your help!! I got it working this morning. The only
difference I had to make was I also needed to keep everything that is in the
OldChile. So that the new text would be first then the old test second.
Oh you mentioned that you have a website, may I have the web address to
check it out?
Thank you again!!
- Andrew
> If your RTF-a contains line breaks and you put a breakpoint on e.g.
>
[quoted text clipped - 72 lines]
> > > > > > Thanks,
> > > > > > Andrew
S.Y.M. Wong-A-Ton - 09 Mar 2006 14:56 GMT
Glad to hear that you got it to work! And since you did, I won't be posting
the solution on my website. But you're free to check out the website at
http://enterprise-solutions.swits.net
---
S.Y.M. Wong-A-Ton
> Thank you for all of your help!! I got it working this morning. The only
> difference I had to make was I also needed to keep everything that is in the
[quoted text clipped - 83 lines]
> > > > > > > Thanks,
> > > > > > > Andrew
Gustavo Hernandez - 16 Apr 2007 22:44 GMT
Hi My name is Gustavo from Monterrey mexico
I have the same problem, but i have one Rich Text field with tables, text in
bold, text in different size, etc...and i would like to copy the values from
one field to another field,
do you think this code could be used also to pass that kind of information?
> If your RTF-a contains line breaks and you put a breakpoint on e.g.
>
[quoted text clipped - 72 lines]
> > > > > > Thanks,
> > > > > > Andrew
S.Y.M. Wong-A-Ton - 17 Apr 2007 07:24 GMT
If the other field is a richt text field, then yes, the same principles
should apply. If you're using InfoPath 2007, you might even get away with
using the InnerXml property to transfer the entire contents in one step; I
haven't tried it out, though. I would say: Just give it a go and see if it
works.
---
S.Y.M. Wong-A-Ton
> Hi My name is Gustavo from Monterrey mexico
>
[quoted text clipped - 79 lines]
> > > > > > > Thanks,
> > > > > > > Andrew
Gustavo Hernandez - 17 Apr 2007 13:56 GMT
Thanks for your quick answer.
And yes both fields are rich text. I'm trying to use your suggestion about
how to transfer text from one field to another, but i'm having problems when
i want to do the replace child instruction. My field "B" does not have any
child node....so,
How can i create a new child for my field "B" where i want to pass the rich
text value from my field "A" ?, i mean i can do a loop for my field "A" and
get the XML data, but i don't understand how to pass every XML data for each
child of my field "A" to my field "B".
> If the other field is a richt text field, then yes, the same principles
> should apply. If you're using InfoPath 2007, you might even get away with
[quoted text clipped - 87 lines]
> > > > > > > > Thanks,
> > > > > > > > Andrew
S.Y.M. Wong-A-Ton - 18 Apr 2007 02:04 GMT
You can do it on a number of ways. Which version of InfoPath are you using?
---
S.Y.M. Wong-A-Ton
> Thanks for your quick answer.
>
[quoted text clipped - 98 lines]
> > > > > > > > > Thanks,
> > > > > > > > > Andrew
Gustavo Hernandez - 23 Apr 2007 17:26 GMT
I'm using InfoPath 2003. Finally i found a way to do it. A little different
than your suggestions, but following your instructions. One thing different
that i did was copy the xml of my field A into a string variable and only
replace the name of the child for the field2 and then do a replace child from
parent node of both fields.
IXMLDOMNode node1 =
doc.DOM.documentElement.selectSingleNode("./my:parentnode/my:Field1");
if (node1 != null)
{
IXMLDOMDocument newchild = doc.CreateDOM();
childtext = node1.xml.ToString();
string newtxtofnode2= childtext.Replace("NameOfChild_1",
"NameOfChild_2");
newchild.loadXML(newtxtofnode2);
oldchild =
doc.DOM.documentElement.selectSingleNode("./my:ParentNode/my:Field2");
oldchild.parentNode.replaceChild(newchild.documentElement, oldchild);
}
And it works !!
Thanks for your help !
> You can do it on a number of ways. Which version of InfoPath are you using?
> ---
[quoted text clipped - 102 lines]
> > > > > > > > > > Thanks,
> > > > > > > > > > Andrew