Dynamically Building Form Templates

M

Matt

I'm wondering if it's possible, using infopath, to programattically generate
and publish an Infopath form template (which will be based on an XML schema)
using an existing XML data document.

Here's an example. I want to dynamically create an Infopath form that will
act as a grocery list. It will have a list of grocery items and a checkbox
next to each item which I'll use to indicate whether it has been purchased.
The schema for a grocery list form to be created would basically be:

<xs:schema>
<xs:element name="groceryList">
<xs:element name="listEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="hasBeenPurchased" type="xs:boolean"/>
<xs:element name="itemName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>

What I want to do is grab a separate existing XML data document (e.g. below)
with a list of item names and produce an infopath form.

<xml data document>
<item>Apples</item>
<item>Oranges</item>
<item>Loaf of bread</item>
</xml data document>

Then I want Infopath to build a form based on the items in that list based
on the schema above. It would look like this:

<Infopath form>
[checkbox]Apples
[checkbox]Oranges
[checkbox]Loaf of bread
</Infopath form>

So that you understand the rationale of why I want to do this, it's because
I don't want end users to have to go into edit mode and manually type in
Apples, Oranges, etc. I want one user to enter item names into a form and
save a resulting XML data document from it. Then I want Infopath to grab the
XML document that was just created and transform it into an Infopath form
that also includes a checkbox in front of each item.

In reality, of course, what I want to do is much more complex than this.
But fundamentally, I can't determine from my reading about Infopath whether
this is feasible or even possible. If it's not possible, please let me know.
You'll save me a bunch of time because I'll stop chasing my tail. If it is
possible, can you offer me any guidance on how this can be done.

Thanks in advance,
Matt
 
S

Scott Roberts [MSFT]

Matt,

If I understand correctly, given an XSD and a XML file you want InfoPath to
generate a form template. Is that correct? InfoPath doesn't provide any
way to do this unfortunately. However, InfoPath form templates are based on
XML standards and the XSF manifest file is documented in our SDK. So, you
could write code to create the forms.

Another possible way to do this would be to create a form template based on
the XSD using the InfoPath Designer. Then, you can write script to automate
InfoPath and call the NewFromSolutionWithData OM method. This method allows
you to create a new form based on an existing form template and and XML
file. That might work for you.

Thanks,
Scott

Matt said:
I'm wondering if it's possible, using infopath, to programattically
generate
and publish an Infopath form template (which will be based on an XML
schema)
using an existing XML data document.

Here's an example. I want to dynamically create an Infopath form that
will
act as a grocery list. It will have a list of grocery items and a
checkbox
next to each item which I'll use to indicate whether it has been
purchased.
The schema for a grocery list form to be created would basically be:

<xs:schema>
<xs:element name="groceryList">
<xs:element name="listEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="hasBeenPurchased" type="xs:boolean"/>
<xs:element name="itemName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>

What I want to do is grab a separate existing XML data document (e.g.
below)
with a list of item names and produce an infopath form.

<xml data document>
<item>Apples</item>
<item>Oranges</item>
<item>Loaf of bread</item>
</xml data document>

Then I want Infopath to build a form based on the items in that list based
on the schema above. It would look like this:

<Infopath form>
[checkbox]Apples
[checkbox]Oranges
[checkbox]Loaf of bread
</Infopath form>

So that you understand the rationale of why I want to do this, it's
because
I don't want end users to have to go into edit mode and manually type in
Apples, Oranges, etc. I want one user to enter item names into a form and
save a resulting XML data document from it. Then I want Infopath to grab
the
XML document that was just created and transform it into an Infopath form
that also includes a checkbox in front of each item.

In reality, of course, what I want to do is much more complex than this.
But fundamentally, I can't determine from my reading about Infopath
whether
this is feasible or even possible. If it's not possible, please let me
know.
You'll save me a bunch of time because I'll stop chasing my tail. If it
is
possible, can you offer me any guidance on how this can be done.

Thanks in advance,
Matt
 
S

Scott Roberts [MSFT]

Btw, this method is documented in our SDK.

Scott Roberts said:
Matt,

If I understand correctly, given an XSD and a XML file you want InfoPath
to generate a form template. Is that correct? InfoPath doesn't provide
any way to do this unfortunately. However, InfoPath form templates are
based on XML standards and the XSF manifest file is documented in our SDK.
So, you could write code to create the forms.

Another possible way to do this would be to create a form template based
on the XSD using the InfoPath Designer. Then, you can write script to
automate InfoPath and call the NewFromSolutionWithData OM method. This
method allows you to create a new form based on an existing form template
and and XML file. That might work for you.

Thanks,
Scott

Matt said:
I'm wondering if it's possible, using infopath, to programattically
generate
and publish an Infopath form template (which will be based on an XML
schema)
using an existing XML data document.

Here's an example. I want to dynamically create an Infopath form that
will
act as a grocery list. It will have a list of grocery items and a
checkbox
next to each item which I'll use to indicate whether it has been
purchased.
The schema for a grocery list form to be created would basically be:

<xs:schema>
<xs:element name="groceryList">
<xs:element name="listEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="hasBeenPurchased" type="xs:boolean"/>
<xs:element name="itemName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>

What I want to do is grab a separate existing XML data document (e.g.
below)
with a list of item names and produce an infopath form.

<xml data document>
<item>Apples</item>
<item>Oranges</item>
<item>Loaf of bread</item>
</xml data document>

Then I want Infopath to build a form based on the items in that list
based
on the schema above. It would look like this:

<Infopath form>
[checkbox]Apples
[checkbox]Oranges
[checkbox]Loaf of bread
</Infopath form>

So that you understand the rationale of why I want to do this, it's
because
I don't want end users to have to go into edit mode and manually type in
Apples, Oranges, etc. I want one user to enter item names into a form
and
save a resulting XML data document from it. Then I want Infopath to grab
the
XML document that was just created and transform it into an Infopath form
that also includes a checkbox in front of each item.

In reality, of course, what I want to do is much more complex than this.
But fundamentally, I can't determine from my reading about Infopath
whether
this is feasible or even possible. If it's not possible, please let me
know.
You'll save me a bunch of time because I'll stop chasing my tail. If it
is
possible, can you offer me any guidance on how this can be done.

Thanks in advance,
Matt
 
J

Joris de Gruyter

I have a similar situation where i have a fixed schema for the data but a
second xml file defining the layout.
So it would be possible to generate an infopath form based on an xml
defining the layout/datafields?

Are there any examples in the SDK getting me on the way to create simple
infopath forms "from code"? In my case i was hoping i could write an XSL to
convert the layout XML to the form, but even if it's with a script i would
be happy already.


thnx



Scott Roberts said:
Matt,

If I understand correctly, given an XSD and a XML file you want InfoPath
to generate a form template. Is that correct? InfoPath doesn't provide
any way to do this unfortunately. However, InfoPath form templates are
based on XML standards and the XSF manifest file is documented in our SDK.
So, you could write code to create the forms.

Another possible way to do this would be to create a form template based
on the XSD using the InfoPath Designer. Then, you can write script to
automate InfoPath and call the NewFromSolutionWithData OM method. This
method allows you to create a new form based on an existing form template
and and XML file. That might work for you.

Thanks,
Scott

Matt said:
I'm wondering if it's possible, using infopath, to programattically
generate
and publish an Infopath form template (which will be based on an XML
schema)
using an existing XML data document.

Here's an example. I want to dynamically create an Infopath form that
will
act as a grocery list. It will have a list of grocery items and a
checkbox
next to each item which I'll use to indicate whether it has been
purchased.
The schema for a grocery list form to be created would basically be:

<xs:schema>
<xs:element name="groceryList">
<xs:element name="listEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="hasBeenPurchased" type="xs:boolean"/>
<xs:element name="itemName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>

What I want to do is grab a separate existing XML data document (e.g.
below)
with a list of item names and produce an infopath form.

<xml data document>
<item>Apples</item>
<item>Oranges</item>
<item>Loaf of bread</item>
</xml data document>

Then I want Infopath to build a form based on the items in that list
based
on the schema above. It would look like this:

<Infopath form>
[checkbox]Apples
[checkbox]Oranges
[checkbox]Loaf of bread
</Infopath form>

So that you understand the rationale of why I want to do this, it's
because
I don't want end users to have to go into edit mode and manually type in
Apples, Oranges, etc. I want one user to enter item names into a form
and
save a resulting XML data document from it. Then I want Infopath to grab
the
XML document that was just created and transform it into an Infopath form
that also includes a checkbox in front of each item.

In reality, of course, what I want to do is much more complex than this.
But fundamentally, I can't determine from my reading about Infopath
whether
this is feasible or even possible. If it's not possible, please let me
know.
You'll save me a bunch of time because I'll stop chasing my tail. If it
is
possible, can you offer me any guidance on how this can be done.

Thanks in advance,
Matt
 
M

Matt

Scott,

Thanks. The NewFromSolutionWithData idea was exactly the guidance I needed.
Being inexperienced with Infopath, it didn't occur to me to take the
approach of having an already existing form with some data already thrown in
(and set to not be editable). I was thinking that it would be necessary to
build the entire form from scratch (which would be a pain obviously).

Thanks again.

Joris de Gruyter said:
I have a similar situation where i have a fixed schema for the data but a
second xml file defining the layout.
So it would be possible to generate an infopath form based on an xml
defining the layout/datafields?

Are there any examples in the SDK getting me on the way to create simple
infopath forms "from code"? In my case i was hoping i could write an XSL to
convert the layout XML to the form, but even if it's with a script i would
be happy already.


thnx



Scott Roberts said:
Matt,

If I understand correctly, given an XSD and a XML file you want InfoPath
to generate a form template. Is that correct? InfoPath doesn't provide
any way to do this unfortunately. However, InfoPath form templates are
based on XML standards and the XSF manifest file is documented in our SDK.
So, you could write code to create the forms.

Another possible way to do this would be to create a form template based
on the XSD using the InfoPath Designer. Then, you can write script to
automate InfoPath and call the NewFromSolutionWithData OM method. This
method allows you to create a new form based on an existing form template
and and XML file. That might work for you.

Thanks,
Scott

Matt said:
I'm wondering if it's possible, using infopath, to programattically
generate
and publish an Infopath form template (which will be based on an XML
schema)
using an existing XML data document.

Here's an example. I want to dynamically create an Infopath form that
will
act as a grocery list. It will have a list of grocery items and a
checkbox
next to each item which I'll use to indicate whether it has been
purchased.
The schema for a grocery list form to be created would basically be:

<xs:schema>
<xs:element name="groceryList">
<xs:element name="listEntry" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="hasBeenPurchased" type="xs:boolean"/>
<xs:element name="itemName" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:element>
</xs:schema>

What I want to do is grab a separate existing XML data document (e.g.
below)
with a list of item names and produce an infopath form.

<xml data document>
<item>Apples</item>
<item>Oranges</item>
<item>Loaf of bread</item>
</xml data document>

Then I want Infopath to build a form based on the items in that list
based
on the schema above. It would look like this:

<Infopath form>
[checkbox]Apples
[checkbox]Oranges
[checkbox]Loaf of bread
</Infopath form>

So that you understand the rationale of why I want to do this, it's
because
I don't want end users to have to go into edit mode and manually type in
Apples, Oranges, etc. I want one user to enter item names into a form
and
save a resulting XML data document from it. Then I want Infopath to grab
the
XML document that was just created and transform it into an Infopath form
that also includes a checkbox in front of each item.

In reality, of course, what I want to do is much more complex than this.
But fundamentally, I can't determine from my reading about Infopath
whether
this is feasible or even possible. If it's not possible, please let me
know.
You'll save me a bunch of time because I'll stop chasing my tail. If it
is
possible, can you offer me any guidance on how this can be done.

Thanks in advance,
Matt
 

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