Enumeration with attribute(s) - InfoPath Dev
in

InfoPath Dev

Enumeration with attribute(s)

Last post 01-21-2005 05:35 PM by Greg Collins. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-20-2005 08:48 AM

    Enumeration with attribute(s)

    I'm generating an InfoPath form from an XML Schema. I can easily use an enumeration to generate a Drop-Down List Box or group of Option Buttons, but I'd like the enumeration element to have attributes as well. I can create a valid schema, but InfoPath treats all of the values as "invalid."

    Example schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="form">
    <xs:complexType>
    <xs:sequence>
    <xs:element ref="q1"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    <xs:element name="q1" type="q1_type"/>

    <xs:complexType name="q1_type">
    <xs:simpleContent>
    <xs:extension base="q1_type_choices">
    <xs:attribute name="q1_attribute" type="xs:string"/>
    </xs:extension>
    </xs:simpleContent>
    </xs:complexType>

    <xs:simpleType name="q1_type_choices">
    <xs:restriction base="xs:positiveInteger">
    <xs:enumeration value="1"/>
    <xs:enumeration value="2"/>
    <xs:enumeration value="3"/>
    </xs:restriction>
    </xs:simpleType>

    </xs:schema>

    q1_type_choices defines the choices (1, 2, or 3). q1_type extends the enumeration with an attribute. The result is a form with a single element (q1) that can contain values 1, 2, or 3 and have an attribute (q1_attribute).

    I can load this schema into InfoPath and drag q1 over as a Drop-Down List Box; however, the properties for the Drop-Down List Box show the values (1, 2, and 3) as "invalid." I cannot change the display values within InfoPath, because it refuses any value.

    I know the alternative is to use elements instead of attributes, but would like to know if there's a trick to allow for an enumeration + attributes before I bail on it.

    Thanks for any suggestions. I'm an InfoPath newbie, so if I've missed something obvious or posted in the wrong forum, please accept my apologies.
  • 01-20-2005 11:40 AM In reply to

    Re: Enumeration with attribute(s)

    Using XML Spy to create a similar schema, I find that I am blocked at adding an attribute to an enumarated node, and I am blocked at adding enumerations to a node with an attribute.

    It looks like, superficially, that what you want to do can't be done. But that doesn't mean that it really can't be done -- you'll need to do some more research and more asking around to find out for sure.

    Greg Collins [InfoPath MVP]
  • 01-21-2005 03:06 PM In reply to

    Re: Enumeration with attribute(s)

    quote:
    Originally posted by Greg Collins

    Using XML Spy to create a similar schema, I find that I am blocked at adding an attribute to an enumarated node, and I am blocked at adding enumerations to a node with an attribute.

    Actually, my example (above) was made using XMLSpy. You can do it too. First create a global simpleType for the enumeration, then create a global complexType that extends the simpleType and adds the attribute, and finally create an element that uses the complexType.

    I researched how to do this in XML Schema. That's not the problem. The problem is that InfoPath won't allow you to edit the display values.

    What's frustrating is that InfoPath actually supports this schema -- it just won't let you changes the values while editing. If you take the example I gave (above) and paste it into XMLSpy, it will be valid. If you then build a form in InfoPath using the schema, you'll see my problem when you try to edit the values for the List Box. But, if you preview the same form in InfoPath, it works! The only problem is in the InfoPath editor.

    I've tried adding the attribute to the XML template, hoping that its presence would be enough to make the enumerated values valid while editing the form...but no luck.

    What's also frustrating me is that this seems like such a simple element. For example:
    <state hometown="yes">California</state>
    where <state> has an enumerated list of possible answers, but also has an attribute. I dunno; it doesn't seem that complex to me.

    As it stands, InfoPath forces me to use something like:
    <state>
    <value>California</value>
    <hometown>yes</hometown>
    </state>
  • 01-21-2005 05:35 PM In reply to

    Re: Enumeration with attribute(s)

    InfoPath doesn't support every construct possible in XSD. Although it is robust, it can be limiting in more complex areas.

    Now, you can agreeably argue that this is not "complex", but unfortunately, that is for InfoPath, and not us to decide.

    I've worked with schemas that seem to work fine in InfoPath but there are issues with full compatibility.

    I don't have an answer for you on this one.

    Greg Collins [InfoPath MVP]
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.