Infopath C# Custom Control Namespace Prefix Problem - InfoPath Dev
in

InfoPath Dev

Infopath C# Custom Control Namespace Prefix Problem

Last post 09-24-2007 04:49 PM by davidair. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 09-12-2007 09:55 AM

    Infopath C# Custom Control Namespace Prefix Problem

     

    I have been trying to resolve a problem for several days now. 

     

    I have built a few custom controls for InfoPath following the article “Creating an InfoPath Custom Control using C# and .NET” at  http://blogs.msdn.com/infopath/archive/2005/04/15/408728.aspx .

      

    I modified the schema form the article above and assigned it the following attributes xmlns:n1”urn:us:um:uc:v3.0”  and assigned it the target namespace “urn:us:um:uc:v3.0”.  The schema is valid in both Spy and InfoPath.

     

    I keep getting an error “Reference to an undeclared namespace prefix ‘n1’”  when passing the XPath string "./n1:street” into domNode.selectSingleNode(“./n1:street”);  However, when I pass in the equivalent XPath string “./*1”  the controls works as expected. 

     

    When I invoke the xDocument.UI.Alert(domNode.xml) or xDocument.UI.Alert(domNode.prefix), InfoPath displays both the correct XML structure and prefix when the domNode is displayed so the prefix is correct.

     

    I have researched the problem in great detail and cannot seem to find a reasonable solution.  I have tried some of the suggestions many of which stated to set the SelectionNamespaces but I don’t see that available with the imported assemblies given in the example above. 

     

    Can someone enlighten me as to the problem with this?  Below is code snippet 

      ThanksJB  

    private void HandleChangesInUI(object sender, EventArgs e)

          {           TextBox senderTbx = (TextBox)sender;

                      this.ChangeDOM("./n1:street", this.streetTbx.Text);

                      }

                                       

          private void ChangeDOM(string xPath, string value)

          {     if (domNode != null)

                {

                Microsoft.Office.Interop.InfoPath.Xml.IXMLDOMNode singleNode = domNode.selectSingleNode(xPath);

               

                      if (singleNode.text != value)

                      {

                            singleNode.text = value;

                      }

                } 

          }    

  • 09-12-2007 10:38 PM In reply to

    Re: Infopath C# Custom Control Namespace Prefix Problem

    It seems like SelectionNamespaces is exactly what you need. It is set as a property on the document. From your code it's not clear as to where domNode is defined.

    You can do the following before calling your selects:

    domNode.ownerDocument.setProperty("SelectionNamespaces", "xmlns:n1=\"ht7p://something\"");

    Of course it's best to this only once as the document will retain this setting. However, no harm is done if you do it many times. Note that you can define several prefixes this way if you space-separate them.

    Good luck!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-13-2007 11:16 AM In reply to

    Re: Infopath C# Custom Control Namespace Prefix Problem

    David

     Thanks for replying.

     I am setting referencing/instatiating the domNode within the Init method  using MicroSoft.Office.Interop.InfoPath.InfoPathControlSite  Node Property.

     per web article  http://blogs.msdn.com/infopath/archive/2006/12/18/creating-complex-infopath-controls-in-c-sharp.aspx.

     Here is the code setting  domNode which references InfoPath's InfoPathControlSite 

    #region InfoPathControl Members
        public void Enable(bool vfEnabled)
        {
        }

        private XDocumentClass xDocument = null;
        public void Init(InfoPathControlSite pControlSite)
        {
            this.domNode = pControlSite.Node;
            this.xDocument = (XDocumentClass)pControlSite.XDocument;
         

       this.RestoreState();
        }

     
        }
        #endregion

    I have tried using xDocument.SetNamedNodeProperty(domNode, "SelectionNamespaces", xmlns:n1="urn:......"");

     I have also tried passing in domNode,ownerDocument into xDocument.SetNamedNodeProperty(domNode, "SelectionNamespaces", xmlns:n1="urn:......"") since I don't see a setProperty() for within  MicroSoft.Office.Interop.InfoPath.InfoPathControlSite .

    If anyone can lead me out of this pit, it would be greatly appreciated.

     

     Thanks

    JB

     

     

  • 09-13-2007 12:19 PM In reply to

    Re: Infopath C# Custom Control Namespace Prefix Problem

    Well, that's strange, you should be able to just do this in your init right after you assign domNode:

    this.domNode.ownerDocument.setProperty("SelectionNamespaces", "xmlns:n1=\"urn\"");

    Is domNode's type IXMLDOMNode? If not, cast it to this type.

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 09-24-2007 11:47 AM In reply to

    Re: Infopath C# Custom Control Namespace Prefix Problem

    David,

     I keep forgetting to post a reply I finally came up with the appropriate code to allow me to set the namespace properties in C#. 

    I used the following code to set the namespace properties...

    MSXML2.IXMLDOMDocument2 domDocument2 =  (MSXML2.IXMLDOMDocument2) this.domNode.getOwner;

    domDocument2.setProperty("SelectionNamespaces", "xmlns:n1=\"urn\"");

     

     Thanks for the help

    Jim

    Filed under:
  • 09-24-2007 04:49 PM In reply to

    Re: Infopath C# Custom Control Namespace Prefix Problem

    Great, I'm glad you finally got the solution!

    David Airapetyan / Software Services Architect
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.