XmlNode from code to datasource - InfoPath Dev
in

InfoPath Dev

XmlNode from code to datasource

Last post 12-29-2006 04:33 AM by nukkumatti. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 12-29-2006 02:16 AM

    XmlNode from code to datasource

    If I in my C# code recieve this XmlNode object with InnerXml:
    <rs:data ItemCount="2" xmlns:rs="urn:schemas-microsoft-com:rowset">
    <z:row Foo="FooValue1" />
    <z:row Foo="FooValue2" />
    </rs:data>
    How can I see it in my Form. Should I create some repeating table? How can I set this XmlNode to some Datasource in my form?
    Best regards,
    Alexander Ekzarov
    Kyiv, Ukraine
    silverlightnet.blogspot.com
  • 12-29-2006 03:27 AM In reply to

    Re: XmlNode from code to datasource

    Hi ekzarov,

    you can try this: Put a textbox control to your infopath view (if it is the first one the name will be field1)

    Now in VS (code) do the following


    string strXml = yourXmlNodeObject.xml
    XmlDocument myXMLDoc = new XmlDocument();
    myXMLDoc.LoadXml(strXml);

    //create new xml dom node (reference to your textboxcontrol)
    IXMLDOMNode myTextBoxControl = thisXDocument.Dom.selectSingleNode("my:myFields/my:field1")
    //fill text box (node)
    myTextBoxControl.text = myXmlDoc.SelectSingleNode("xPath to the node you want the value of").InnerText;

    Does it help ?
    Listen to Motörhead cos they play Rock'n Roll :)
  • 12-29-2006 03:58 AM In reply to

    Re: XmlNode from code to datasource

    Thanks, but I need put this data in list... Can I do this?
    Best regards,
    Alexander Ekzarov
    Kyiv, Ukraine
    silverlightnet.blogspot.com
  • 12-29-2006 04:29 AM In reply to

    Re: XmlNode from code to datasource

    Not to sure if I understand you correct but....

    so the FOO tags in you xmlNode object are repeating.
    What you then can do is to first count how many of these tags you have. Then put a repeating section in your infopath view and put a textbox control into this repeating section.

    No you need to create as many repeating sections as you counted tags in your xml string, this you can do with the following code:

    int requiredsections = XmlNodeObject.SelectNodes("your xPathString").length

    Now you can just hide the complete repeating sections, put a dropdownlist to your view and bind it to the textboxcontrol within your hidden section.


    for(int i = 1; i < requiredSections; i++)
    {
    string myRepeat = thisXDocument.DOM.selectSingleNode("my:myFields/my:group1/my:group2").xml;
    IXMLDOMDocument oXml = thisXDocument.CreateDOM();
    oXml.async = false;
    oXml.loadXML(myRepeat);
    IXMLDOMNode parentNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:group1");
    parentNode.appendChild(oXml.documentElement);
    }


    Like this you have as many repeating sections as needed including the textbox controls

    now just fill the textbox controls

    for(int j = 1; j < requiredSections; j++)
    {
    thisXDocument.DOM.selectSingleNode("my:myFields/my:group1/my:group2[" + j + "]/field1").text = XmlNodeObject.selectSingleNode(yourXPathString).InnerText;
    }
    [/code]
    If you now want to represent these data in a better way just hide the complete repeating sections from the view, enter a dropdownlist to your view and bind it to the textbox control within your repeating section, like this you have all values in the ddl.

    Does this help ?
    Listen to Motörhead cos they play Rock'n Roll :)
  • 12-29-2006 04:33 AM In reply to

    Re: XmlNode from code to datasource

    Now if you want to represent the data in a smarter view hide the repeating section, put a dropdownlist control to your view and bind it to the textboxcontrol within your repeating section.
    Listen to Motörhead cos they play Rock'n Roll :)
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.