简体   繁体   中英

Can I make my XML Schema (XSD) give me VS Intellisense with elements that have *any* name?

Below is a sample XSD and sample XML. The XSD is written for XML like this:

<Columns>
    <Column label="etc..."></Column>
</Columns>

I would like the XSD to allow elements with any name instead of just "Column". What I really want is intellisense to work in Visual Studio so that I can enter any element name instead of "Column" and still get prompted for the various column attributes. Is this possible? I'm just looking for intellisense. I don't need to actually validate the XML using the schema.

Sample XML:

<?xml version="1.0" encoding="utf-8" ?>
<Columns name="FindPatient" label="Find Patient">
    <Name label="Patient Name" display="yes" order="1"/>
    <MRN label="MRN #" display="yes" order="2"/>
    <BirthDate label="Birth Date" format="shortdate" align="right" display="yes" order="3"/>
    <SSN label="SSN" format="hiddenSsn" display="yes" order="4" notSortable="yes"/>
    <DateOfService label="Date Of Service" format="shortdate" align="right" display="no" order="5"/>
    <AdmitDate label="Admit Date" format="shortdate" align="right" display="no" order="6"/>
    <DischargeDate label="Discharge Date" format="shortdate" align="right" display="no" order="7"/>
    <Address label="Address" display="yes" order="8"/>
    <Facility label="Facility" display="yes" order="9"/>
</Columns>

Sample XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="ColumnConfiguration" targetNamespace="http://example.com/columnconfiguration" xmlns="http://example.com/columnconfiguration" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:simpleType name="yesNo">
        <xs:restriction base="xs:string">
            <xs:enumeration value="yes"/>
            <xs:enumeration value="no"/>
        </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="Column">
        <xs:attribute name="label" type="xs:string" use="required"/>
        <xs:attribute name="display" type="yesNo" use="required"/>
        <xs:attribute name="order" type="xs:integer" use="required"/>
        <xs:attribute name="format" type="format" use="optional"/>
        <xs:attribute name="align" type="xs:string" use="optional"/>
        <xs:attribute name="tooltip" type="xs:string" use="optional"/>
    </xs:complexType>
    <xs:complexType name="Columns">
        <xs:sequence>
            <xs:element name="Column" type="Column" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="Columns" type="Columns"/>
</xs:schema>

replace

<xs:complexType name="Columns">
    <xs:sequence>
        <xs:element name="Column" type="Column" minOccurs="1" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

with

solution : allow any child element without specifying them

<xs:complexType name="Columns">
    <xs:sequence>
        <xs:any minOccurs="1"/>
    </xs:sequence>
</xs:complexType>

solution 2 : allow some well defined childs

<xs:complexType name="Columns">
    <xs:choice minOccurs="1" maxOccurs="unbound">
        <xs:element name="Column" type="Column" minOccurs="1" maxOccurs="unbounded"/>
        <!-- add other xs:element here -->
    </xs:choice>
</xs:complexType>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM