Hi,
in order to add xmlnode, try to select first node from the initial xml, and
call the Clone method and assign tie return value to the new XmlNode
variable. With this action, you get new node, with the same format as the
initial nodes. Then, add values to these node, and try the metrod
insertBefore in order to add the node to the data source.
Darko Milevski, MCAD
> Hi,
>
[quoted text clipped - 33 lines]
>
> - Morten
Morten Wennevik - 03 Nov 2006 09:59 GMT
Hi Darko,
I'm afraid this method does not work for me.
using the code below I get an error on appendChild saying the new node
(child) is unexpected according to content model of parent node
this.XDOM = window.external.Window.XDocument.DOM;
this.XDOM.setProperty("SelectionNamespaces",
'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/2006-06-16T08:03:28"
xmlns:xd="http://schemas.microsoft.com/office/infopath/2003"');
var parent = this.XDOM.selectSingleNode("//my:ListeLookup");
var child = parent.cloneNode(true);
parent.appendChild(child);
How do I get XDocument to accept the new node?
> Hi,
>
[quoted text clipped - 46 lines]
>>
>> - Morten

Signature
Happy Coding!
Morten Wennevik [C# MVP]
darko - 03 Nov 2006 10:43 GMT
Hi,
If I asume that youre xml is like this
<ListLookup>
<Value></Value>
<Value></Value>
....
</ListLookup>
youre code should be
this.XDOM = window.external.Window.XDocument.DOM;
var beforeNode = this.XDOM.selectSingleNode("//my:Value"); //selects the
first value node
var child = beforeNode .cloneNode(true);
this.XDOM.insertBefore(child,beforeNode);
you dont need to setProperty, becouse the cloneNode will make the new
addNode child to be same as the selected one.
Darko Milevski, MCAD
> Hi Darko,
>
[quoted text clipped - 69 lines]
> >>
> >> - Morten
Morten Wennevik - 03 Nov 2006 11:29 GMT
Hi Darko,
The Xml structure is
<my:nyKunde><my:ListeLookup></myListeLookup></my:nyKunde> and the
DropDownList is set to use the repeating field ListeLookup for filling the
list.
However, since I couldn't add another ListeLookup field in the designed I
assumed the list was filled with sub nodes to ListeLookup, which was not
true and any child node of ListeLookup was unexpected according to content
model of parent...
Adding the new node to nyKunde instead of ListeLookup solved the problem.
insertBefore would probably work as well as the node would then be added
to the parent of ListeLookup (or parent of Value in your case).
I do, however, need setProperty as otherwise selectSingleNode failes as
'my' is not a defined namespace. The code runs in a custom task pane.
Thanks for your help.
Morten
> Hi,
>
[quoted text clipped - 102 lines]
>> Happy Coding!
>> Morten Wennevik [C# MVP]

Signature
Happy Coding!
Morten Wennevik [C# MVP]