1

我的任务是为特定解决方案替换 xsd。但是,我不断收到“在这种情况下不支持元素”。

这是原始的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>";

这是我应该用以下内容替换它的内容:

<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>

该架构是由其他人制作的,我应该能够替换它。不幸的是,它不是那样工作的,我对此知之甚少。

我应该改变吗

 <MonthlyValues> 

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

并添加

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

之后?实际上,我试过了,但没有用,但是我有类似的事情要做吗?

4

1 回答 1

1

XSD 是另外一回事……您似乎对 XSD 不熟悉,所以让您开始的最快方法可能是从您的示例 XML 生成 XSD。调整生成的以匹配 XML。使用下面的 XSD 作为起点。

<?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.

于 2012-07-27T18:40:09.607 回答