我尝试在zillow“SearchResults.xsd”上运行Visual Studio的XSD.EXE实用程序来生成c#或vb.net类,但我没有运气,正在寻求帮助。我一直在收到错误(见下文)。这是我从http://www.zillow.com/howto/api/GetDeepSearchResults.htm下载的原始文件:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.zillow.com/static/xsd/SearchResults.xsd"
xmlns:ZillowTypes="http://www.zillow.com/static/xsd/ZillowTypes.xsd">
<xsd:import namespace="http://www.zillow.com/static/xsd/ZillowTypes.xsd"
schemaLocation="/vstatic/4/static/xsd/ZillowTypes.xsd" />
<xsd:element name="searchresults">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="request">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="address" type="xsd:string" />
<xsd:element name="citystatezip" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="message" type="ZillowTypes:Message" />
<xsd:element minOccurs="0" name="response">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="results">
<xsd:complexType>
<xsd:sequence>
<xsd:element minOccurs="1" maxOccurs="unbounded" name="result" type="ZillowTypes:SimpleProperty" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
以下是我在Visual Studio 2010中尝试XSD.EXE时遇到的错误:
C:\Users\username\Documents>xsd /classes SearchResults.xsd
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 4.0.30319.1]
Copyright (C) Microsoft Corporation. All rights reserved.
Schema validation warning: Type 'http://www.zillow.com/static/xsd/ZillowTypes.xsd:Message' is not declared. Line 25, position 6.
Schema validation warning: Type 'http://www.zillow.com/static/xsd/ZillowTypes.xsd:SimpleProperty' is not declared. Line 33, position 12.
Warning: Schema could not be validated. Class generation may fail or may produce
incorrect results.
Error: Error generating classes for schema 'SearchResults'.
- The datatype 'http://www.zillow.com/static/xsd/ZillowTypes.xsd:Message' is missing.
看起来所有内容都在ZillowTypes.xsd中定义,所以我很难过。
答案 0 :(得分:4)
设置存在一些问题。从XSD文件的位置开始,该文件应该位于http://www.zillow.com/static/xsd/SearchResults.xsd
上面的XSD使用导入来引用另一个xsd,该导入具有解析为http://www.zillow.com/vstatic/4/static/xsd/ZillowTypes.xsd的相对uri /vstatic/4/static/xsd/ZillowTypes.xsd
- 但此URL不可解除引用(404)!!
如果您尝试http://www.zillow.com/static/xsd/ZillowTypes.xsd,则会找到拼图的第2部分,即ZillowTypes.xsd。
由于这些错误,您需要将两个XSD文件下载到本地计算机以修复它们。
首先下载 SearchResults.xsd ,然后下载 ZillowTypes.xsd ;把它们放在同一个文件夹里。
通过更改以下行修改 SearchResults.xsd :
<xsd:import namespace="http://www.zillow.com/static/xsd/ZillowTypes.xsd" schemaLocation="/vstatic/4/static/xsd/ZillowTypes.xsd" />
为:
<xsd:import namespace="http://www.zillow.com/static/xsd/ZillowTypes.xsd" schemaLocation="ZillowTypes.xsd" />
然后你遇到了另一个问题。 ZillowTypes.xsd 包含无效的元素声明!所以编辑下面的decl:
<xsd:complexType name="investmentBuyingBlock">
<xsd:sequence>
<xsd:element name="buying" minOccurs="0" maxOccurs="unbounded">
<xsd:sequence>
<xsd:element name="year" type="xsd:integer"/>
<xsd:element name="rentalIncome" type="xsd:integer"/>
<xsd:element name="otherIncome" type="xsd:integer"/>
<xsd:element name="mortgagePayment" type="xsd:integer"/>
<xsd:element name="principal" type="xsd:integer"/>
<xsd:element name="interest" type="xsd:integer"/>
<xsd:element name="hoaFees" type="xsd:integer"/>
<xsd:element name="propertyTaxes" type="xsd:integer"/>
<xsd:element name="utilities" type="xsd:integer"/>
<xsd:element name="renovations" type="xsd:integer"/>
<xsd:element name="maintainCosts" type="xsd:integer"/>
<xsd:element name="homeOwnerInsurance" type="xsd:integer"/>
<xsd:element name="managementFees" type="xsd:integer"/>
<xsd:element name="advertisingCosts" type="xsd:integer"/>
<xsd:element name="otherExpenses" type="xsd:integer"/>
<xsd:element name="totalExpenses" type="xsd:integer"/>
<xsd:element name="opportunityCostInitial" type="xsd:integer"/>
<xsd:element name="opportunityCostYearly" type="xsd:integer"/>
<xsd:element name="depreciationBuilding" type="xsd:integer"/>
<xsd:element name="depreciationrenovation" type="xsd:integer"/>
<xsd:element name="totalBenefit" type="xsd:integer"/>
<xsd:element name="totalProfitLoss" type="xsd:integer"/>
</xsd:sequence>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
要:
<xsd:complexType name="investmentBuyingBlock">
<xsd:sequence>
<xsd:element name="buying" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="year" type="xsd:integer"/>
<xsd:element name="rentalIncome" type="xsd:integer"/>
<xsd:element name="otherIncome" type="xsd:integer"/>
<xsd:element name="mortgagePayment" type="xsd:integer"/>
<xsd:element name="principal" type="xsd:integer"/>
<xsd:element name="interest" type="xsd:integer"/>
<xsd:element name="hoaFees" type="xsd:integer"/>
<xsd:element name="propertyTaxes" type="xsd:integer"/>
<xsd:element name="utilities" type="xsd:integer"/>
<xsd:element name="renovations" type="xsd:integer"/>
<xsd:element name="maintainCosts" type="xsd:integer"/>
<xsd:element name="homeOwnerInsurance" type="xsd:integer"/>
<xsd:element name="managementFees" type="xsd:integer"/>
<xsd:element name="advertisingCosts" type="xsd:integer"/>
<xsd:element name="otherExpenses" type="xsd:integer"/>
<xsd:element name="totalExpenses" type="xsd:integer"/>
<xsd:element name="opportunityCostInitial" type="xsd:integer"/>
<xsd:element name="opportunityCostYearly" type="xsd:integer"/>
<xsd:element name="depreciationBuilding" type="xsd:integer"/>
<xsd:element name="depreciationrenovation" type="xsd:integer"/>
<xsd:element name="totalBenefit" type="xsd:integer"/>
<xsd:element name="totalProfitLoss" type="xsd:integer"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
通过替换
重新运行XSD命令行 SearchResults.xml
带
SearchResults.xsd ZillowTypes.xsd
它应该有效(至少XSD现在有效)。