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;
}
}
}