Question

I have been tasked to replace the xsd for a particular solution. However, I keep getting an "element is not supported in this context."

Here is the original xsd:

    public const string Xsd = @"
<xs:schema attributeFormDefault='unqualified' elementFormDefault='qualified'     xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <xs:element name='DataRow'>
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs='unbounded' name='Data'>              
          <xs:complexType>
            <xs:attribute name='Site' type='xs:string' use='required' />
            <xs:attribute name='Month_Num' type='xs:unsignedShort' use='required' />
            <xs:attribute name='Numerator' type='xs:unsignedByte' use='required' />
            <xs:attribute name='Data_Indicator' type='xs:string' use='required' />
            <xs:attribute name='Budgeted' type='xs:unsignedByte' use='required' />
            <xs:attribute name='Executive_Comments' type='xs:string' use='required' />
            <xs:attribute name='Fleet_Executive_Comments' type='xs:string' use='required' />
         </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>";

Here is what I am supposed to be replacing it with:

<xs:schema attributeFormDefault='unqualified' elementFormDefault='qualified' xmlns:xs='http://www.w3.org/2001/XMLSchema'>
  <MonthlyValues>
    <MonthlyValue IndicatorName='name' LocationName='name' GroupingName='name' Year='MonthNum.Value.Year' Month='MonthNum.Value.Month' Numerator='Numerator' Budget='Budget'>
    </MonthlyValue>
 </MonthlyValues>
</xs:schema>

The schema was made by someone else and I was supposed to just be able to replace it. Unfortunately its not working out that way and I know very little about it.

should I change

 <MonthlyValues> 

to

<xs:element name='MonthlyValues> and keep the 
<xs:sequence>
   <xs:element maxOccurs='unbounded' name='MonthlyValues'>
      <xs:complexType>

and add the

<MonthlyValue IndicatorName='name' LocationName='name' GroupingName='name' Year='MonthNum.Value.Year' Month='MonthNum.Value.Month' Numerator='Numerator' Budget='Budget'>
</MonthlyValue>

afterward? Actually, I tried that and it didn't work, but is there something similar I have to do?

Was it helpful?

Solution

XSD is something else... you do seem to be new to XSD so maybe the quickest way to get you started is to generate an XSD from your sample XML. Tweak the generated to match the XMLs. Use the XSD below as a starting point.

<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="MonthlyValues">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="MonthlyValue">
          <xsd:complexType>
            <xsd:simpleContent>
              <xsd:extension base="xsd:string">
                <xsd:attribute name="IndicatorName" type="xsd:string" use="required" />
                <xsd:attribute name="LocationName" type="xsd:string" use="required" />
                <xsd:attribute name="GroupingName" type="xsd:string" use="required" />
                <xsd:attribute name="Year" type="xsd:string" use="required" />
                <xsd:attribute name="Month" type="xsd:string" use="required" />
                <xsd:attribute name="Numerator" type="xsd:string" use="required" />
                <xsd:attribute name="Budget" type="xsd:string" use="required" />
              </xsd:extension>
            </xsd:simpleContent>
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

You should rely on an editor to help you through the learning... Eclipse, Netbeans, etc. come with decent editors, and free.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top