Looping the Code - InfoPath Dev
in

InfoPath Dev

Looping the Code

Last post 06-23-2008 04:58 AM by Shiva. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 06-09-2008 09:22 AM

    Looping the Code

    Hi all,

                I am developing a tool using Infopath 2007. I do have a XSD schema which contains more than 40 controls with hierarchy. I am able to access each and every controls for populating the XML values by programmatically.But the code is repetative.SO more than 120 lines of code needed. Is there anyway to have the looping method? so that i can shrink my program.

    Thanks,

    Thiyagarajan N.

  • 06-23-2008 04:58 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Hello Thiyagarajan,

    To reduce your code you have to create one secondary file with sourceXPath and destinationXPath fields.

    Example:

    <MappingNodes>

              <MappingNode>

                       <Mapping sourceXPath ="" destinationXPath=""/>

                       <Mapping sourceXPath ="" destinationXPath=""/>

              </MappingNode>

    </MappingNodes>

     

    Code: Here is the code,

    //Get the list of nodes from secondary dom.

    IXMLDOMNodeList MappingNodes = thisXDocument.GetDOM("DOM Name").selectNodes( "/ MappingNodes/MappingNode/Mapping");

    foreach (IXMLDOMNode MappingNode in MappingNodes)

      {

    //Get the source XPath of node    

    string sourceXPath = MappingNode.selectSingleNode("@sourceXPath");

    //Get the destination XPath of node

    string destinationXPath = MappingNode.selectSingleNode("@destinationXPath");

    //Get the source value from secondary dom

    string sourceValue = thisXDocument.GetDOM("DOM Name").selectSingleNode(sourceXPath);

    //Set the source vlaue to destination node

    thisXDocument.DOM.selecteSingleNode(destinationXPath, sourceValue);

    }

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