Error in code - InfoPath Dev
in

InfoPath Dev

Error in code

Last post 11-02-2005 11:07 PM by Coita Thierry. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 11-02-2005 05:35 AM

    Error in code

    Hi,

    I have some probleme I wan't to replace a node in my form but I don't how if I try like this:
    IXMLDOMNode Muster = thisXDocument.DOM.selectSingleNode("/Essai/Muster");
    string xml =Muster.xml;
    XmlDocument oldMuster = new XmlDocument();
    oldMuster.LoadXml(xml);
    XPathNavigator oldMuster2 = oldMuster.CreateNavigator();
    XslTransform xslt = new XslTransform();
    xslt.Load("mustertransform.xsl");
    XmlUrlResolver resolve= new XmlUrlResolver();
    StringWriter result= new StringWriter();
    xslt.Transform(oldMuster2,null,result, resolve);

    IXMLDOMDocument2 newDocument = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    newDocument.loadXML(result.ToString());

    IXMLDOMNode NewMuster = newDocument.selectSingleNode("/");

    Muster.parentNode.replaceChild(NewMuster, Muster);


    But that make me the following error:
    quote:
    System.ArgumentException
    This operation can not be performed with a Node of type DOCUMENT.


    The error is made by the last line!

    Any Idea about what is the problem?

    Thanks 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
  • 11-02-2005 06:53 AM In reply to

    Could you try fetching the stack trace of the exception.

    That would make debugging alot easier.

    put try catch around the code and in the general exception e (or ArgumentException e) write

    System.Diagnostics.Trace.WriteLine(e.StackTrace);

    Check the debug output with any system output viewer. I prefer DebugView by SystemInternals:
    http://www.sysinternals.com/Utilities/DebugView.html

    I use this method alot when working with smart clients or sharepoint.

    Be aware that the above data will only be intercepted if you build in debug mode (as in not release mode)

    hth
    //AndersR



  • 11-02-2005 01:44 PM In reply to

    Hi Thierry,
    Try this out for the last two lines
    IXMLDOMNode NewMuster = newDocument.documentElement;
    Muster.parentNode.replaceChild(NewMuster, Muster);


    Agni
    InfoPath Dev India
  • 11-02-2005 11:07 PM In reply to

    Hi,

    Thanks for the reply!

    Great software AndersR I will try it!

    Ok so I have make an error in
    IXMLDOMNode NewMuster = newDocument.selectSingleNode("/");

    I select the entire xml with the declaration line and infopath say that I can replace by a complete XML!

    So if I do:
    IXMLDOMNode NewMuster = newDocument.selectSingleNode("/Case");

    That works!

    Stupid error but interessant answer thanks one more times!

    ++

    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
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.