the timestamp matters with SelectionNamespace xmlns:my ???

W

waffle93

I created a form and added some VBScript code to it. After having
difficulties with the code I deleted all of it. Now I am adding code back to
the form but cannot reference any of the fields in it, apparently because it
does not recognize the namespace declaration.

The error I receive is:

After troubleshooting I figured out that you can't just copy in a substitute
for the namespace declaration that InfoPath automatically puts in your script
the first time you write to it. I tested this by creating a new, blank form
and added one field and one button. If I use the auto-generated namespace
declaration then clicking the button will display the value of the text box.
If I copy over the namespace declaration (with a different timestamp) then I
get the same error as above.

The code is as simple as this:

---------------------------------
'<namespacesDefinition>
XDocument.DOM.setProperty "SelectionNamespaces",
"xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-03-03T19:04:56"""
'</namespacesDefinition>

Sub CTRL2_5_OnClick(eventObj)
myText = XDocument.DOM.selectSingleNode("/my:myFields/my:dummyField").Text
msgbox myText
End Sub
---------------------------------


....so what is going on here? If the timestamp in the namespace declaration
is sensitive to each form then how do I re-create this for my form?


Also...curious...does the form query schemas.microsoft.com every time it
opens to translate the namespace?
 
G

Greg Collins

No, the form does not query the URL in the namespace definition. The
definition can be anything. URLs are often used because that URL offers more
information on the schema.

The namespace definition must match exactly. "XYZ" does not match "ABC", nor
does "2008-03-03T19:03:56" match "2008-03-01T05:23:54" The entire string, as
a whole, within the quotes constitutes the definition of that namespace. If
you substitute in another one then you have a different namespace. This is
no different than human names. My name is Greg Collins. There are other
people named Greg Collins in this world. So when you use the name Greg
Collins -- who are you referring to? When you use the namespace "my", what
are you referring to? The definition helps to keep all that straight.

If you have lost the definition, extract your form files and get a copy of
it from the manifest.xsf, template.xml, view1.xml, or myschema.xsd.
 
W

waffle93

Thank you Greg. I also noticed that if I click on any of the fields from my
Data Source and then click on the tab 'Advanced' that there is a namespace
definition there. I copied that to my code and it works.

Thanks for the explanation, that makes sense. As a footnote it appears the
namespace definition is created using the date/time the form was created.

-ken
 
G

Greg Collins

That is correct. The date/time of the form creation is indeed used in the
namespace definition. It's a means to help ensure (as much as possible) that
the definition is unique, while still being more useful than a GUID.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top