What's the easiest way to poke data into a form? - InfoPath Dev
in

InfoPath Dev

What's the easiest way to poke data into a form?

Last post 10-06-2005 05:18 PM by RobW. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-05-2005 11:51 PM

    • RobW
    • Not Ranked
    • Joined on 10-05-2005
    • Australia
    • Posts 2

    What's the easiest way to poke data into a form?

    Hi all,

    First post from a new to infopath member. Apologies if this is covered elsewhere

    I'm trying to do somethiing very similar to the structural editing sample form in the developer's reference. Basically, I want to select some data from a list of values in the task pane and pass the selected items back into the forms xml. No worries with any of the task pane stuff; I have the DHTML all working and know all about window.external.Window. XDocument to pass the selections back in.

    The problem I am having is in inserting the selections into the forms underlying xml.

    I can think of two ways of doing it. One is to access the node I want to change via the DOM property of the XDocument along the lines of:

    var Dom = Xdocument.DOM;
    var contextnode = Dom.selectSingleNode("//my:context");
    var newnode = dom.createNode(1, "my:context", "my:");
    contextnode.parentNode.appendChild(newnode);

    But when I try this I get a complaint that the node is 'unexpected'. What does that mean? Is it unable to be validated against the schema or is it a namespace clash?

    The other way is to try to retrieve the node definition from the manifest a la the example in the structural editing form. Trouble is, the sample form creates an enormous selectSingleNode XPath statement that terminates in something like "chooseFragment[@parent ='blah']". When I examine my .xsf file the parent attribute is nowhere to be found, instead the subtree is under an 'innerFragment' attribute.

    The .xsf reference is circular at best in the way it explains things and I am stuck. Could someone please tell me the best way to simply insert nodes into my form's XML?

    Thanks

    Rob


  • 10-06-2005 05:28 AM In reply to

    Re: What's the easiest way to poke data into a form?

    I believe you are correct in your assessment, but I have not tried that code above. I created a form not that long ago that did a lot of work with a custom task pane and moved data captured from there over. This is what I did. This method will take a string of XML and a the path to where it should be inserted.

    Sub CreateRow(sXML, sParentNodePath)

    'Create a new row
    dim oXml
    set oXml = XDocument.CreateDOM()
    oXml.async = false
    oXml.loadXML(sXML)

    'add the row to the DOM
    XDocument.DOM.selectSingleNode(sParentNodePath).appendChild(oXml.documentElement)

    End Sub

    For instance if my XML structure was <Policies><Policy></Policy><Policy></Policy></Policies>

    sXML = "<Policy></Policy>"
    sParentNodePath = "//Policies"

    From a maintainability standpoint this code is not the best, I personally do not like it because the XML string gets hard coded into your script or managed code and if you schema gets modified, you must remember to go modify this code.

    Another thing you could look into is the Call XDocument.View.ExecuteAction using the "xCollection::insert" parameter. This method does not suffer from the disadvantage that I mentioned above.
    Jason
    http://www.k2distillery.com/
  • 10-06-2005 05:18 PM In reply to

    • RobW
    • Not Ranked
    • Joined on 10-05-2005
    • Australia
    • Posts 2

    Re: What's the easiest way to poke data into a form?

    Hey Thanks!

    Whilst your suggestion didn't directly resolve the issue, it has put me on the right path.

    Always interesting to see how others approach similar problems - I hadn't considered the view element.

    Thanks again!
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.