Create Node with multiple fields - InfoPath Dev
in

InfoPath Dev

Create Node with multiple fields

Last post 05-09-2005 11:45 AM by Hawouax. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 05-04-2005 07:09 AM

    Create Node with multiple fields

    Hi,

    I'm programming with InfoPath since 1 week and I have some problems to create node manually with JScript.

    Here is my structure :

    + tbl_info (repeating)
    ...
    + tbl_attendees (repeating)
    - ID
    - Id_Attendee
    - Attendee_name
    - Attendee_status

    When tbl_attendees have only 1 field i'm able to create a new node by using the following code :

    + tbl_attendees (repeating)
    - Attendee_name

    var xmlNodeText = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tbl_info/d:tbl_attendees/@Attendee_name");
    var xmlParent = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tbl_info/d:tbl_attendees");
    var newNode;

    newNode = XDocument.DOM.createNode
    (1, "Attendee_name", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-04
    -01T18:40:51");
    newNode.text = "Christian";
    xmlParent.appendChild(newNode);

    How can I do the same things with few fields in tbl_attendees ???

    Thanks a lot

    Christian Côté



  • 05-04-2005 08:53 PM In reply to

    Re: Create Node with multiple fields

    Hi Christian Côté, Welcome to the Board!
    You are almost near to getting it done,
    Instead of creating each node individually you can create a DOM of "d:tbl_attendees" and replace the original "d:tbl_attendees" with the new one.
    Here is how you do it
    var sXml = "<d:tbl_attendees xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields' >
    <Attendee_name>Christian</Attendee_name>
    <Attendee_Number>Number</Attendee_Number>
    </d:tbl_attendees>"

    Load this into a Dom
    var oXml = XDocument.CreateDOM();
    oXml.async = false;
    oXml.loadXML(sXml);
    Now replace your old "d:tbl_attendees" with the new one.
    xmlParent.ParentNode.ReplaceChild(oXml.documentElement, xmlParent)

    Hope this Helps!


    Agni
    InfoPathDev India
  • 05-05-2005 01:14 PM In reply to

    Re: Create Node with multiple fields

    Hi Agni,

    Here is the code I modified but I still got the error :
    Element 'http://schemas.microsoft.com/office/infopath/2003/ado/dataFields}
    tbl_attendees' is unexpected according to content model of parent
    element 'http://schemas.microsoft.com/office/infopath/2003/ado/dataFields}
    tbl_attendees'.


    var sRepeatingNode = "<d:tbl_attendees xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields'><ID>1</ID><Id_attendee>1</Id_attendee><Attendee_name>Christian Côté</Attendee_name><Attendee_status>1</Attendee_status></d:tbl_attendees>";

    var xmlParent = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:tbl_info/d:tbl_attendees");

    var oXml = XDocument.CreateDOM();
    oXml.async = false;
    oXml.loadXML(sRepeatingNode);
    xmlParent.appendChild(oXml.documentElement);

    Do you have an idea why it's happening ???

    Thanks a million

    Christian

  • 05-05-2005 09:28 PM In reply to

    Re: Create Node with multiple fields

    Hi Christian,
    You made small mistake here, in my sample I replaced whole of "d:tbl_attendees" node with the new node. But you are appending the new "d:tbl_attendees" node to the old "d:tbl_attendees" node which is wrong according to the schema.

    In my sample we have prepared a new "d:tbl_attendees" node to replace the existing node.

    xmlParent.ParentNode.ReplaceChild(oXml.documentElement, xmlParent)

    Hope you got it!



    Agni
    InfoPathDev India
  • 05-09-2005 11:45 AM In reply to

    Re: Create Node with multiple fields

    Thank you very much Agni,

    I finally got it.

    Thanks for your help.
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.