replace primary datasource - InfoPath Dev
in

InfoPath Dev

replace primary datasource

Last post 09-10-2009 03:30 AM by deepak483. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 07-14-2005 02:48 AM

    replace primary datasource

    Hi,

    I wan't to refresh my primary datasource with the data of an xml but how to replace the structure of root element : Case

    I have try this:

    thisXDocument.DOM.selectSingleNode("/ns1:Case").xml= ModGeschaeft;

    ModGeschaeft is an IXMLDOMNode

    but VS say that : thisXDocument.DOM.selectSingleNode("/ns1:Case").xml

    is read only

    Is there any solution to accomplish this?

    Thanks in advance

    ++

    Thierry

    Every moment hesitated is a moment gone for life!!! Think about it
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
  • 07-14-2005 03:17 AM In reply to

    Re: replace primary datasource

    Hi Thierry,
    Just select the root node and replace it with the new one.

    //get the root node
    IxmlDomNode rootNode = thisXDocument.DOM.selectSingleNode("/ns1:Case");
    //replace it with the new root node
    rootNode.parentNode.replacechild(newNode, rootNode);

    Agni
    InfoPathDev India
  • 07-14-2005 06:33 AM In reply to

    Re: replace primary datasource

    Hi Agni,

    Thanks for your help it's very nice!

    but I have one question how to put an XmlDocument in a IXMLDOMNode?

    If I try with text(IXMLDOMNode) and tostring(XmlDocument) that make me an error:
    ModGeschaeft.text = Xmlr.OuterXml.ToString();
    the error:
    quote:
    Text is not allowed in the context of element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-14T14-11-47}Case' according to DTD/Schema.
    Expecting: http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-14T14-11-47}Geschaeft.

    at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.set_text(String value)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.set_text(String value)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.set_text(String value)
    at Geschaeft2.Geschaeft2.Modifier_OnClick(DocActionEvent e) in c:\documents and settings\tc\bureau\st gallen\visual studio projects\geschaeft2\formcode.cs:line 205
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)



    If you need more ask me!

    Thanks a lot!

    ++

    Thierry


    Every moment hesitated is a moment gone for life!!! Think about it
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
  • 07-14-2005 06:46 AM In reply to

    Re: replace primary datasource

    I think if I give me code you can better understand:


    IXMLDOMNode res = e.Source;
    XmlDocument XmlSave = new XmlDocument();
    XmlSave.LoadXml(res.xml);
    XPathNavigator toto= XmlSave.CreateNavigator();
    XslTransform xslt = new XslTransform();
    xslt.Load("addnamespace.xsl");
    XmlUrlResolver resolve= new XmlUrlResolver();
    StringWriter result= new StringWriter();
    xslt.Transform(toto,null,result, resolve);
    //appel WS et résultat du WS
    //string andry =result.ToString();
    IXMLDOMNode ModGeschaeft = thisXDocument.DOM.selectSingleNode("/ns1:Case");
    IXMLDOMNode Original = thisXDocument.DOM.selectSingleNode("/");
    XmlDocument Xmlr = new XmlDocument();
    Xmlr.LoadXml(result.ToString());
    //Xmlr.Save(@"C:\xml1.xml");

    ModGeschaeft.text = Xmlr.OuterXml;
    XmlDocument Xmlt = new XmlDocument();
    Xmlt.LoadXml(ModGeschaeft.xml);
    Xmlt.Save(@"C:\xml2.xml");
    Original.parentNode.replaceChild(ModGeschaeft,Original);


    the result of xsl transform:

    <?xml version="1.0" encoding="utf-16"?>
    <ns1:Case ns1:noNamespaceSchemaLocation="http://zefix.powernet.ch/Schema/HRG.xsd" ns1:Amt="150"
    ns1:CHNR="CH-150.3.000.465-2" ns1:Gnr="129" ns1:Gyear="1995" ns1:Kanton="NW" ns1:Lang="1" ns1:Nr="NW-129-1995"
    ns1:SitzNr="1509" ns1:Stempel="2005-07-06T17:46:42" ns1:Visum="Exp" ns1:inBearb="0"
    ns1:valid="2" xmlns:ns1="http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-06-14T14-11-47">
    <ns1:Geschaeft>
    <ns1:Firma>Pilatus Flugzeugwerke AG</ns1:Firma>
    <ns1:Bemerkung>Löschung einer Prokura</ns1:Bemerkung>
    <ns1:Sitz ns1:bfs="1509">Stans</ns1:Sitz>
    <ns1:TBx>
    <ns1:TB>
    <ns1:Nr>136</ns1:Nr>
    <ns1:Datum>1995-02-08</ns1:Datum>
    </ns1:TB>
    </ns1:TBx>
    <ns1:SHAB>
    <ns1:Nr>34</ns1:Nr>
    <ns1:Datum>1995-02-17</ns1:Datum>
    <ns1:Seite>934</ns1:Seite>
    </ns1:SHAB>
    </ns1:Geschaeft>
    <ns1:Search>
    <ns1:SearchAIM>Pilatus Flugzeugwerke AG Löschung einer Prokura</ns1:SearchAIM>
    </ns1:Search>
    <ns1:AV ns1:GF="2" ns1:RF="3" ns1:type="Verfuegung">
    </ns1:AV>
    </ns1:Case>


    ++

    Thierry

    Every moment hesitated is a moment gone for life!!! Think about it
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
  • 08-02-2005 11:15 PM In reply to

    Re: replace primary datasource

    Ok I have do some testing thanks Agni your answer is good but now my question is :

    I have the result of my transformation in a XmlDocument

    But now how to convert an XmlDocument to an IXMLDOMNode with C#?

    For the text in the markup it's not a problem but for replace all the XML structure I don't understand how to proceed?

    For example I have try things like this (Xmlr is the XmlDocument):

    IXMLDOMNode ModGeschaeft = Xmlr.SelectSingleNode("/ns1:Case");

    but that always make me an error of compilation! Any idea?

    Thanks a lot for your help!

    ++

    Thierry

    Every moment hesitated is a moment gone for life!!! Think about it
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
  • 08-04-2005 07:45 AM In reply to

    Re: replace primary datasource

    Hi Thierry, Sorry for being so late. Here is the code snippet to convert to a node
    IXMLDOMDocument2 newDocument = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    newDocument.loadXML(Xmlr.xml);
    newDocument.setProperty("SelectionNamespaces", "NameSpaces you are using for this xml");
    IXMLDOMNode oNode = newDocument.SelectSingleNode("/ns1:Case");

    Hope this Helps!

    Agni
    InfoPath Dev India
  • 08-05-2005 02:33 AM In reply to

    Re: replace primary datasource

    Hi Agni,

    Thanks a lot that work great!

    Just a little things, for fun! you say:
    quote:
    newDocument.loadXML(Xmlr.xml);


    But with an XMLDocument you don't have this method!

    So I have change by:
    quote:
    newDocument.loadXML(Xmlr.OuterXml);


    ++

    Thierry

    Every moment hesitated is a moment gone for life!!! Think about it
    Infopath 2007, Langage: C#2.0 (Modèle Objet 2003)
    merci de lire ceci
  • 09-10-2009 03:30 AM In reply to

    Re: replace primary datasource

    Hi There,

    This post gave me the hope that actually we can change XSN files at run time.

    If any one drops by this, refer to the below link to get to know how to solve the above issue with Infopath 2007

     http://blogs.msdn.com/infopath/archive/2006/06/06/619143.aspx

    I am copying the part of the code...

     

    string xpath = "/my:myFields/my:field1";
    IXMLDOMNode field1 = thisXDocument.DOM.selectSingleNode(xpath);
    string oldValue = field1.text; // Read
    field1.text = "New Value";     // Write
     
    Here's how to do the same thing using the new object model:
     
    string xpath = "/my:myFields/my:field1";
    XPathNavigator field1 = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);

    string oldValue = field1.Value; // Read
    field1.SetValue(“New Value”);   // Write

     

     

    Thanks to Agni and Ned (I guess this is the author)

     

    Regards

    Deepak

    ---
    Deepak N Naidu
    "Giant Leap Starts With One Small Step"
    http://deepakn.info/blog
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.