Group:  Other Microsoft Office Products ยป microsoft.public.infopath
Thread: Problem selecting nodes

DotNetBag
.NET Development Newsgroups

HTVi
TV Discussion Newsgroups

Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Rising Antivirus 2006

Problem selecting nodes
pearsond 14.07.2006 17:39:02
Hi,

I am using the following code to open a new form from within an InfoPath
form and set a value of a field. However, I receive the following error:
System.Runtime.InteropServices.COMException
Reference to undeclared namespace prefix: 'my'.

Here is my code:
XDocumentsCollection docCollection = thisApplication.XDocuments;
XDocument newForm = docCollection.NewFromSolution([ at ]"C:\Documents and
Settings\PearsonD\My Documents\MultiForm\Supporting.xsn");
newForm.DOM.selectSingleNode("/my:myFields/my:field1").text = "hello";

Here is xml from the form I'm trying to populate:
<?xml version="1.0" encoding="UTF-8"?>
<?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="11.0.6565"
PIVersion="1.0.0.0"
href="file:///C:\Documents%20and%20Settings\PearsonD\My%20Documents\Supporting.xsn"
name="urn:schemas-microsoft-com:office:infopath:Supporting:-myXSD-2006-07-13T14-17-26" ?>
<?mso-application progid="InfoPath.Document"?>
<my:myFields
xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-07-13T14:17:26" xml:lang="en-us">
<my:field1>Test Data</my:field1>
</my:myFields>

I greatly appreciate any assistance. Thank you.
RE: Problem selecting nodes
S.Y.M. Wong-A-Ton 14.07.2006 19:44:01
Try setting the namespace "my" by setting the "SelectionNamespaces" property
using "setProperty" on the DOM, before you start using XPath expressions to
find nodes. Search this newsgroup on "SelectionNamespaces" to find out how to
do this.
---
S.Y.M. Wong-A-Ton


"pearsond" wrote:

[Quoted Text]
> Hi,
>
> I am using the following code to open a new form from within an InfoPath
> form and set a value of a field. However, I receive the following error:
> System.Runtime.InteropServices.COMException
> Reference to undeclared namespace prefix: 'my'.
>
> Here is my code:
> XDocumentsCollection docCollection = thisApplication.XDocuments;
> XDocument newForm = docCollection.NewFromSolution([ at ]"C:\Documents and
> Settings\PearsonD\My Documents\MultiForm\Supporting.xsn");
> newForm.DOM.selectSingleNode("/my:myFields/my:field1").text = "hello";
>
> Here is xml from the form I'm trying to populate:
> <?xml version="1.0" encoding="UTF-8"?>
> <?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="11.0.6565"
> PIVersion="1.0.0.0"
> href="file:///C:\Documents%20and%20Settings\PearsonD\My%20Documents\Supporting.xsn"
> name="urn:schemas-microsoft-com:office:infopath:Supporting:-myXSD-2006-07-13T14-17-26" ?>
> <?mso-application progid="InfoPath.Document"?>
> <my:myFields
> xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-07-13T14:17:26" xml:lang="en-us">
> <my:field1>Test Data</my:field1>
> </my:myFields>
>
> I greatly appreciate any assistance. Thank you.
RE: Problem selecting nodes
pearsond 17.07.2006 13:50:02
Thank you for pointing me in the right direction. I was able to successfully
execute the xpath expressions using the following code:

// Access the Application and collection.
XDocumentsCollection docCollection = thisApplication.XDocuments;

// Create a new form from the passes URL.
XDocument newForm = docCollection.NewFromSolution([ at ]"C:\Documents and
Settings\PearsonD\My Documents\MultiForm\Supporting.xsn");

// re-type
IXMLDOMDocument2 newFormDOM = (IXMLDOMDocument2) newForm.DOM;

// Set namespace property
newFormDOM.setProperty("SelectionNamespaces",
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-07-13T14:17:26\" xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

// Set field1.
newFormDOM.selectSingleNode("/my:myFields/my:field1").text = "hello";

"S.Y.M. Wong-A-Ton" wrote:

[Quoted Text]
> Try setting the namespace "my" by setting the "SelectionNamespaces" property
> using "setProperty" on the DOM, before you start using XPath expressions to
> find nodes. Search this newsgroup on "SelectionNamespaces" to find out how to
> do this.
> ---
> S.Y.M. Wong-A-Ton
>
>
> "pearsond" wrote:
>
> > Hi,
> >
> > I am using the following code to open a new form from within an InfoPath
> > form and set a value of a field. However, I receive the following error:
> > System.Runtime.InteropServices.COMException
> > Reference to undeclared namespace prefix: 'my'.
> >
> > Here is my code:
> > XDocumentsCollection docCollection = thisApplication.XDocuments;
> > XDocument newForm = docCollection.NewFromSolution([ at ]"C:\Documents and
> > Settings\PearsonD\My Documents\MultiForm\Supporting.xsn");
> > newForm.DOM.selectSingleNode("/my:myFields/my:field1").text = "hello";
> >
> > Here is xml from the form I'm trying to populate:
> > <?xml version="1.0" encoding="UTF-8"?>
> > <?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="11.0.6565"
> > PIVersion="1.0.0.0"
> > href="file:///C:\Documents%20and%20Settings\PearsonD\My%20Documents\Supporting.xsn"
> > name="urn:schemas-microsoft-com:office:infopath:Supporting:-myXSD-2006-07-13T14-17-26" ?>
> > <?mso-application progid="InfoPath.Document"?>
> > <my:myFields
> > xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-07-13T14:17:26" xml:lang="en-us">
> > <my:field1>Test Data</my:field1>
> > </my:myFields>
> >
> > I greatly appreciate any assistance. Thank you.

Home | Search | Terms | Imprint | Contact
Newsgroups Reader - provided by WiredBox.Net