cvc-complex-type.2.4.a: 从元素日开始发现无效内容。 {HiTemp} 之一是预期的
cvc-complex-type.2.4.a: Invalid content was found starting with element day. One of {HiTemp} is expected
我正在尝试用简单的 XSD 编写一个简单的 XML 文件。
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<forecast week="June 1st 2016"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="forecast.xsd">
<day name="Monday">
<HiTemp>84</HiTemp>
<LoTemp>74</LoTemp>
<Wind>SSE 18 mph</Wind>
<Humidity>59%</Humidity>
<DewPoint>68 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>4 of 10</UVIndex>
<Sunrise>6:01 AM</Sunrise>
<Sunset>8:49 PM</Sunset>
</day>
<day name="Tuesday">
<HiTemp>89</HiTemp>
<LoTemp>77</LoTemp>
<Wind>NW 6 mph</Wind>
<Humidity>68%</Humidity>
<DewPoint>54 degrees</DewPoint>
<Visibility>8 miles</Visibility>
<UVIndex>6 of 10</UVIndex>
<Sunrise>6:03 AM</Sunrise>
<Sunset>8:51 PM</Sunset>
</day>
<day name="Wednesday">
<HiTemp>91</HiTemp>
<LoTemp>76</LoTemp>
<Wind>NE 27 mph</Wind>
<Humidity>48%</Humidity>
<DewPoint>44 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>8 of 10</UVIndex>
<Sunrise>6:05 AM</Sunrise>
<Sunset>8:53 PM</Sunset>
</day>
<day name="Thursday">
<HiTemp>91</HiTemp>
<LoTemp>74</LoTemp>
<Wind>SSE 20 mph</Wind>
<Humidity>61%</Humidity>
<DewPoint>68 degrees</DewPoint>
<Visibility>7 miles</Visibility>
<UVIndex>5 of 10</UVIndex>
<Sunrise>6:07 AM</Sunrise>
<Sunset>8:55 PM</Sunset>
</day>
<day name="Friday">
<HiTemp>97</HiTemp>
<LoTemp>76</LoTemp>
<Wind>SE 10 mph</Wind>
<Humidity>79%</Humidity>
<DewPoint>54 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>8 of 10</UVIndex>
<Sunrise>6:10 AM</Sunrise>
<Sunset>8:57 PM</Sunset>
</day>
</forecast>
还有我的XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="forecast">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="HiTemp" type="xs:integer"/>
<xs:element name="Lotemp" type="xs:integer"/>
<xs:element name="Wind" type="xs:string"/>
<xs:element name="Humidity" type="xs:string"/>
<xs:element name="Dewpoint" type="xs:string"/>
<xs:element name="Visibility" type="xs:string"/>
<xs:element name="UVIndex" type="xs:string"/>
<xs:element name="Sunrise" type="xs:time"/>
<xs:element name="Sunset" type="xs:time"/>
</xs:sequence>
<xs:attribute name="week" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
我在 oXygen 中遇到的错误是
cvc-complex-type.2.4.a: Invalid content was found starting with
element day
. One of {HiTemp}
is expected.
这可能很简单。我一直在寻找其他答案,但我无法确定是什么导致了我的问题,因为它通常与其他答案中的其他问题有关。
您的 XSD 需要进行多项调整,包括:
- 添加了缺少的
day
包装器元素和 name
属性。
- 更正了
Lotemp
和 Dewpoint
的大小写。
这是您的 XSD 更新,以便能够成功验证您的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="day" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="HiTemp" type="xs:integer"/>
<xs:element name="LoTemp" type="xs:integer"/>
<xs:element name="Wind" type="xs:string"/>
<xs:element name="Humidity" type="xs:string"/>
<xs:element name="DewPoint" type="xs:string"/>
<xs:element name="Visibility" type="xs:string"/>
<xs:element name="UVIndex" type="xs:string"/>
<xs:element name="Sunrise" type="xs:string"/>
<xs:element name="Sunset" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="week" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
我正在尝试用简单的 XSD 编写一个简单的 XML 文件。
这是我的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<forecast week="June 1st 2016"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="forecast.xsd">
<day name="Monday">
<HiTemp>84</HiTemp>
<LoTemp>74</LoTemp>
<Wind>SSE 18 mph</Wind>
<Humidity>59%</Humidity>
<DewPoint>68 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>4 of 10</UVIndex>
<Sunrise>6:01 AM</Sunrise>
<Sunset>8:49 PM</Sunset>
</day>
<day name="Tuesday">
<HiTemp>89</HiTemp>
<LoTemp>77</LoTemp>
<Wind>NW 6 mph</Wind>
<Humidity>68%</Humidity>
<DewPoint>54 degrees</DewPoint>
<Visibility>8 miles</Visibility>
<UVIndex>6 of 10</UVIndex>
<Sunrise>6:03 AM</Sunrise>
<Sunset>8:51 PM</Sunset>
</day>
<day name="Wednesday">
<HiTemp>91</HiTemp>
<LoTemp>76</LoTemp>
<Wind>NE 27 mph</Wind>
<Humidity>48%</Humidity>
<DewPoint>44 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>8 of 10</UVIndex>
<Sunrise>6:05 AM</Sunrise>
<Sunset>8:53 PM</Sunset>
</day>
<day name="Thursday">
<HiTemp>91</HiTemp>
<LoTemp>74</LoTemp>
<Wind>SSE 20 mph</Wind>
<Humidity>61%</Humidity>
<DewPoint>68 degrees</DewPoint>
<Visibility>7 miles</Visibility>
<UVIndex>5 of 10</UVIndex>
<Sunrise>6:07 AM</Sunrise>
<Sunset>8:55 PM</Sunset>
</day>
<day name="Friday">
<HiTemp>97</HiTemp>
<LoTemp>76</LoTemp>
<Wind>SE 10 mph</Wind>
<Humidity>79%</Humidity>
<DewPoint>54 degrees</DewPoint>
<Visibility>10 miles</Visibility>
<UVIndex>8 of 10</UVIndex>
<Sunrise>6:10 AM</Sunrise>
<Sunset>8:57 PM</Sunset>
</day>
</forecast>
还有我的XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="forecast">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="HiTemp" type="xs:integer"/>
<xs:element name="Lotemp" type="xs:integer"/>
<xs:element name="Wind" type="xs:string"/>
<xs:element name="Humidity" type="xs:string"/>
<xs:element name="Dewpoint" type="xs:string"/>
<xs:element name="Visibility" type="xs:string"/>
<xs:element name="UVIndex" type="xs:string"/>
<xs:element name="Sunrise" type="xs:time"/>
<xs:element name="Sunset" type="xs:time"/>
</xs:sequence>
<xs:attribute name="week" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
我在 oXygen 中遇到的错误是
cvc-complex-type.2.4.a: Invalid content was found starting with element
day
. One of{HiTemp}
is expected.
这可能很简单。我一直在寻找其他答案,但我无法确定是什么导致了我的问题,因为它通常与其他答案中的其他问题有关。
您的 XSD 需要进行多项调整,包括:
- 添加了缺少的
day
包装器元素和name
属性。 - 更正了
Lotemp
和Dewpoint
的大小写。
这是您的 XSD 更新,以便能够成功验证您的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified"
vc:minVersion="1.1">
<xs:element name="forecast">
<xs:complexType>
<xs:sequence>
<xs:element name="day" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="HiTemp" type="xs:integer"/>
<xs:element name="LoTemp" type="xs:integer"/>
<xs:element name="Wind" type="xs:string"/>
<xs:element name="Humidity" type="xs:string"/>
<xs:element name="DewPoint" type="xs:string"/>
<xs:element name="Visibility" type="xs:string"/>
<xs:element name="UVIndex" type="xs:string"/>
<xs:element name="Sunrise" type="xs:string"/>
<xs:element name="Sunset" type="xs:string"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="week" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>