XML with Inline Schema Supported in Excel?

I need to create a simple XML file (user list) with XSD so that this XML can be imported into Excel (2010+). The fields represented by this XML are dynamic, it depends on the user what fields he wants / needs. The list can be long and I have about 40 fields for the user to select.

Excel builds its table columns based on XML schema. If fields are missing in the first row, they will be added to the table in the wrong order. So a schematic is required! Since XML is query-based, the XML schema must be inline.

Based on every article I can find about inline schema I created the following ... but it will destroy every validator. Excel won't accept it either.

<?xml version="1.0" encoding="UTF-8"?>

<users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="#local">
  <xs:schema id="local" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="users">
      <xs:complexType>
        <xs:sequence>
          <xs:any processContents="skip" namespace="http://www.w3.org/2001/XMLSchema" minOccurs="0" maxOccurs="1"/>
          <xs:element ref="user" minOccurs='1' maxOccurs='unbounded'/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

    <xs:element name="user">
      <xs:complexType>
        <xs:sequence>
          <xs:element ref="firstname" minOccurs='0' maxOccurs='1'/>
          <xs:element ref="lastname" minOccurs='0' maxOccurs='1'/>
          <xs:element ref="phone" minOccurs='0' maxOccurs='1'/>
        </xs:sequence>
      </xs:complexType>
    </xs:element>

    <xs:element name="firstname" type="xs:string"/>
    <xs:element name="lastname" type="xs:string"/>
    <xs:element name="phone" type="xs:string"/>

  </xs:schema>

  <user>
    <lastname>Doe</lastname>
    <phone>123456789</phone>
  </user>
  <user>
    <firstname>John</firstname>
    <lastname>Something</lastname>
  </user>
  <user>
    <firstname>Jesus</firstname>
    <lastname>Christ</lastname>
    <phone>987654321</phone>
  </user>
</users>

      

What the hell am I doing wrong? It seems so simple ...

+3


source to share





All Articles