xs:type

M

Miguel de Melo

Hi,

I have an XML Schema containing inherited complex types, and xs:elements
using @type of the top complex type, meaning, any child complex type can be
an instance of that element by declaring the complex type name using xsi:type
..

If I write the xml by hand, and validate against the xml schema, works
really well.

Using infopath I can import the schema and the data structure is displayed
in the form designer, although there is no apparent way to allow users to
select the xsi:type the instance of that element will be using.

Has anybody used xsi:type with infopath before, or know any way to define
element instance selectors in infopath ?

Thanks
Miguel
 
D

David Dean

InfoPath doesn't recognize this type of schema element. Although you can
import the schema, you will probably not be able to bind the element to any
editable control.

Your schema would probably need to use an <xs:choice> element to allow for a
choice of elements with different datatypes. InfoPath interprets this as a
Choice control. Alternatively, your schema can declare different elements
with different datatypes, then use conditional formatting within InfoPath to
hide or show controls based on the contents of another element that
identifies the desired datatype.
 
M

Miguel de Melo

Hi David,

We’ve tried creating schemas with xs:choice, but unfortunately it represents
illegal XML Schema syntax and (not sure about info path) but most schema
validation tools would fail to validate the schema (even Visual Studio). But
the main problem is that we need the xml to bind to an object model.
So we have no option but to use xsi:type, to define an instance of a complex
type that inherits from another, so we can deserialize the xml back to the
object model.


Is it possible to create dynamic controls using visual basic or c# in Info
path ? This way we might be able to analyse the options and create the
controls on the fly . . .

Thanks
 
D

David Dean

InfoPath won't let you dynamically add/remove controls, but they can be
hidden or shown using conditional formatting.

If I am to understand your problem correctly, you intend to deserialize the
form XML into the appropriate .NET class instances. Unless you are using
special attributes on your class definitions, I presume that your schema
would need to use different element names to represent different derived
class types so that the deserializer can recognize the correct type of the
instance. You expect InfoPath to be able to show the correct controls
depending on the type of the instance; i.e. if you extend a type by adding a
couple of properties, the UI for the derived type would include a couple of
additional controls bound to these properties.

You might be able to accomplish this in InfoPath using the following
approach and restrictions:
- Use a single element name for the root node of the document
- Where a parent node can contain instances of different complex types,
define an xs:sequence that includes an xs:element for each possible type,
making sure the minOccurs attribute is set to 0.
- In the InfoPath form, add an optional section for each element that
contains the appropriate controls for an element of that type.

To deserialize the XML, you will probably need to include some custom
attributes so that the different element names are deserialized into the
correct types and mapped into the appropriate property of the parent instance.
 

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