0

Ok, so not even sure how to ask this, but I'm looking for help on how to create an XML schema file so that when a xml file is loaded into a dataset based on said schema, the data in the tables is as I expect it to be.

Here is the XML data:

<Cabinet>
   <Name>DANCE</Name>
   <MappedTypes>
      <TypeMapInfo>
         <TypeName>HIP HOP</TypeName>
         <DefaultInstitution />
         <DefaultAuthority>511</DefaultAuthority>
         <DefaultDocumentName />
      </TypeMapInfo>
      <TypeMapInfo>
         <TypeName>JITTERBUG</TypeName>
         <DefaultInstitution />
         <DefaultAuthority>511</DefaultAuthority>
         <DefaultDocumentName />
      </TypeMapInfo>
   </MappedTypes>
</Cabinet>

and basically, I would like it to show up like this in a datatable:

Cabinet      | Type Name | DefaultInstitution | DefaultAuthority | DefaultDocumentName
Dance        | HIP HOP   |                    | 511              |                    
Dance        | JITTERBUG |                    | 511              |                      

So Far this is what I have, but it only loads the first type name listed under the cabinet:

<xs:element maxOccurs="unbounded" name="Cabinet">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Name" type="xs:string" />
      <!--<xs:element name="MappedTypes"/>
      <xs:element name="TypeMapInfo"/>-->
      <xs:element  name="TypeName" type="xs:string" />
      <xs:element name="DefaultInstitution" type="xs:string" />
      <xs:element name="DefaultAuthority" type="xs:unsignedShort" />
      <xs:element name="DefaultDocumentName" />
    </xs:sequence>
  </xs:complexType>
</xs:element>
2
  • There are several sites where you can generate a schema from an instance. Once you have one, you can adjust it to your needs. This is one of them: freeformatter.com/xsd-generator.html Paste your XML there, and get the schema it generates. Use that to validate your data. After that you can change the types, add restrictions, etc. Commented Jun 6, 2014 at 0:58
  • I used visual studio to generate the XML schema. What I posted above is what visual studio made for me. However the data in the XML file is not loading the way I would like it too. What I'm looking for help in is how to make the schema produce the results that I have listed above. Commented Jun 6, 2014 at 1:04

1 Answer 1

1

You have to correct your xsd if you want that your xml will be valid for it, probably your data table only is showing up the <Name> element because is the only element in the xsd which is well defined for your xml.

The following xsd fit your xml try with it:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://your_namespace" 
           targetNamespace="http://your_namespace" 
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified">

    <xs:element name="Cabinet" maxOccurs="unbounded">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Name" type="xs:string"/>
                <xs:element name="MappedTypes">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="TypeMapInfo" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="TypeName" type="xs:string"/>
                                        <xs:element name="DefaultInstitution" type="xs:string"/>
                                        <xs:element name="DefaultAuthority" type="xs:unsignedShort"/>
                                        <xs:element name="DefaultDocumentName" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

EDIT:

I review your question and reading your comments again I realize that maybe you're looking for a XML that fits your XSD instead of XSD that fits your XML as I respond in the first attempt. So If you have an XSD like:

<xs:element maxOccurs="unbounded" name="Cabinet">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="Name" type="xs:string" />
      <xs:element  name="TypeName" type="xs:string" />
      <xs:element name="DefaultInstitution" type="xs:string" />
      <xs:element name="DefaultAuthority" type="xs:unsignedShort" />
      <xs:element name="DefaultDocumentName" />
    </xs:sequence>
  </xs:complexType>
</xs:element>

you must change your XML to:

<Cabinet>
 <Name>DANCE</Name>
 <TypeName>HIP HOP</TypeName>
 <DefaultInstitution/>
 <DefaultAuthority>511</DefaultAuthority>
 <DefaultDocumentName/>
</Cabinet>
<Cabinet>
 <Name>DANCE</Name>
 <TypeName>JITTERBUG</TypeName>
 <DefaultInstitution/>
 <DefaultAuthority>511</DefaultAuthority>
 <DefaultDocumentName/>
</Cabinet>

Hope this helps,

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.