Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / November 2006

Tip: Looking for answers? Try searching our database.

How to manipulate InfoPath form's datasource

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Morten Wennevik - 01 Nov 2006 11:37 GMT
Hi,

I'm trying to dynamically add items in a DropDownList.  The DropDownList  
uses a repeating field my:ListeLookup to fill the values and this field  
has no values in it to begin with.  I add values to the xml in an external  
program using this code

        Dim doc As New System.Xml.XmlDocument()
        doc.LoadXml(XML43.XmlString)
       
        Dim nsmgr As New XmlNamespaceManager(doc.NameTable)
        nsmgr.AddNamespace("my",  
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-06-16T08:03:28")
       
        Dim node As XmlNode = doc.SelectSingleNode("my:nyKunde/my:ListeLookup",  
nsmgr)
       
        Dim newNode As XmlNode = doc.CreateNode(XmlNodeType.Element,  
"my:NewName",  
"http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-06-16T08:03:28")
        newNode.InnerText = "Hello World"

        node.AppendChild(newNode)
       
        XML43.XmlString = doc.OuterXML

In a pane in the InfoPath form this xml is replaced with the existing  
using replaceChild but I get this error

Element  
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-06-16T08:03:28}NewName'  
is unexpected according to content element of parent element  
'{http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-06-16T08:03:28}List
eLookup
'

How can I get NewName to be expected?

- Morten
darko - 01 Nov 2006 14:33 GMT
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]

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.