我正在尝试制作XML架构,而不是取得太多成功。有一个我不明白的构造......这是我到目前为止的模式,接下来是我试图为它做的XML文件..任何建议?
<?xml version="1.0" encoding="utf-16"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="CorbelFile">
<xsd:complexType>
<xsd:sequence>
<xsd:group ref="Project" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:group name="Project">
<xsd:sequence>
<xsd:element name="ADProductID"
type="xsd:string" />
<xsd:element name="ADProductID"
type="xsd:string" />
<xsd:element name="ADProductName"
type="xsd:string" />
<xsd:element name="ADProductVersion"
type="xsd:string" />
<xsd:element name="ADProjectId"
type="xsd:string" />
<xsd:element name="ADProjectName"
type="xsd:string" />
<xsd:element name="ADFileLoc"
type="xsd:string" />
<xsd:group ref="Answers"
minOccurs="0"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:group>
<xsd:group name="Answers">
<xsd:sequence>
<xsd:element name="var"/>
</xsd:sequence>
</xsd:group>
</xsd:schema>
<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<CorbelFile>
<Project>
<ADProductId>28359</ADProductId>
<ADProductName>IDP 403(b)</ADProductName>
<ADProductVersion>7.0</ADProductVersion>
<ADProjectId>00010001</ADProjectId>
<ADProjectName>Independence Dental Center PS</ADProjectName>
<ADFileLoc>C:\Program Files\Relius\Docs\dp_data\1\0\00010001.ck2</ADFileLoc>
<answers>
<Var Ld="PKGA" />
<Var Ld="BKTHead2" />
<Var Ld="SingleSpace" />
<Var Ld="MarginRagged" />
<Var Ld="SPDTimes" />
<Var Ld="BKTTimes" />
<Var Ld="PlanNameB" />
<Var Ld="ERPYEnds" />
<Var Ld="InitialEffDate" />
<Var Ld="2000SafHarEnhancMatch" />
<Var Ld="StateCollege" />
<Var Ld="CharityCorp" />
<Var Ld="ExceptEEPartTime">Independence</Var>
<Var Ld="ExceptEEStudent">Missouri</Var>
<Var Ld="ExceptEENonResAliens">11500 East 23rd Street</Var>
<Var Ld="ExceptEECollBargAgree">64052</Var>
<Var Ld="EEExclNA">(816) 254-7200</Var>
<Var Ld="NoExclElig">43-1118440</Var>
<Var Ld="ACP2000CurrentYR">001</Var>
<Var Ld="ExceptEEHR" />
<Var Ld="1YRAndHalfServReq">Profit Sharing Plan and Trust</Var>
<Var Ld="YRServReq">Independence Dental Center, Inc.</Var>
<Var Ld="Age21">INDEPENDENCE DENTAL CENTER, INC.</Var>
<Var Ld="AgeOther">PROFIT SHARING PLAN AND TRUST</Var>
<Var Ld="1stDayMonth">September 30</Var>
<Var Ld="1stDayPYNextFollowing">October 1</Var>
<Var Ld="CompExclOT">September 30</Var>
<Var Ld="CompExcl414s">October 1</Var>
<Var Ld="CompSalRed">December 12, 1963</Var>
<Var Ld="NASRA" />
<Var Ld="ACPPreYR" />
<Var Ld="QNECPY" />
<Var Ld="QNEC500HRs" />
<Var Ld="QNECYOS" />
<Var Ld="ShareDiscrYOSEndPY" />
<Var Ld="ForfeitRedERContr" />
<Var Ld="7YRGrade" />
<Var Ld="MinDistCYAftr2000">Brad Babcock</Var>
<Var Ld="MinDistCYAftr2001">Lauren Carr</Var>
<Var Ld="NServPriorEffDate" />
<Var Ld="1999SafeHarbContr">John Smith</Var>
<Var Ld="NRD1stDayMonth" />
<Var Ld="NRAPartAnnivBDay1" />
<Var Ld="NERD" />
<Var Ld="NDistrJSA" />
<Var Ld="Multi2ndERCityStateZip" />
<Var Ld="2000SafHarNonElectOthrPln" />
<Var Ld="TermDistrImmed" />
<Var Ld="YTransRoll403b" />
<Var Ld="LoansNA" />
<Var Ld="Loans10000DeMin" />
<Var Ld="LoansSRALimit" />
<Var Ld="YDirInv" />
<Var Ld="DirInvRollTrans" />
<Var Ld="HrdshipSafeHarb401k" />
<Var Ld="EmployerPhone" />
<Var Ld="NMulti2ndER" />
<Var Ld="Multi2ndERName" />
<Var Ld="YMulti3rdER" />
<Var Ld="Multi3rdERStreet" />
<Var Ld="Multi4thEIN" />
<Var Ld="Multi5thERStreet" />
<Var Ld="SumPlanOnly" />
<Var Ld="YPSBKT" />
<Var Ld="YSBJPA" />
<Var Ld="NAPriorCurrentYRTestMethP" />
<Var Ld="NHCPContrPost973Perc" />
<Var Ld="NComplyGATTUSERRASBJPATRA" />
<Var Ld="NSafeHarbMatch" />
<Var Ld="DeferBenOption" />
<Var Ld="PayOldAnnuitDate">59 1/2</Var>
<Var Ld="NAHrdshipSafeHarb401k">60th</Var>
<Var Ld="VServ3" />
<Var Ld="VServ6" />
<Var Ld="VPerc1" />
<Var Ld="VPerc6" />
<Var Ld="ACPCurrentPre97" />
<Var Ld="ACPCurrentPre98" />
<Var Ld="YDiscrMC4PercCompPost99PY" />
<Var Ld="EG_Hrdshp_Suspensn_Red_N" />
<Var Ld="EG_Suspensn_2001_NA" />
</answers>
</Project>
<Project>
<ADProductId>83</ADProductId>
<ADProductName>IDP Money Purchase/Target</ADProductName>
<ADProductVersion>2.0</ADProductVersion>
<ADProjectId>00010002</ADProjectId>
<ADProjectName>Independence Dental Center MP</ADProjectName>
<ADFileLoc>C:\Program Files\Relius\Docs\dp_data\2\0\00010002.ck2</ADFileLoc>
<answers />
</Project>
<Project>
<ADProductId>24581</ADProductId>
<ADProductName>IDP Revised SA</ADProductName>
<ADProductVersion>10.0</ADProductVersion>
<ADProjectId>000102C9</ADProjectId>
<ADProjectName>2010 - Hanover - Trustee</ADProjectName>
<ADFileLoc>C:\Program Files\Relius\Docs\dp_data\9\C\000102C9.ck2</ADFileLoc>
<answers>
<Var Ld="NShortAmendment" />
<Var Ld="PASMM" />
<Var Ld="PACorpResol" />
<Var Ld="PTimes" />
<Var Ld="SPDTimes" />
<Var Ld="CorbelClientNameA">AMERICAN FIDUCIARY CORPORATION</Var>
<Var Ld="SA401kProfitSharing" />
<Var Ld="EmployerNameA">Hanover Obstetrics & Gynecology, Inc.</Var>
<Var Ld="Corp" />
<Var Ld="EmployerStreet">135 Webster Street</Var>
<Var Ld="EmployerCity">Hanover</Var>
<Var Ld="EmployerState">Massachusetts</Var>
<Var Ld="EmployerZip">02339</Var>
<Var Ld="EmployerPhone">(781) 878-7020</Var>
<Var Ld="EIN">04-2477545</Var>
<Var Ld="PlanNumOther">001</Var>
<Var Ld="PlanNameA">Hanover Obstetrics & Gynecology, Inc.</Var>
<Var Ld="PlanNameB">401(k) Profit Sharing Plan</Var>
<Var Ld="AmendmentOne" />
<Var Ld="AmendDate">August 1, 2010</Var>
<Var Ld="NWitnessLine" />
<Var Ld="PlanAdminERAddress" />
<Var Ld="IndivTrustee" />
<Var Ld="DesignatedAmendments" />
<Var Ld="401KfeaturesNoChange" />
<Var Ld="DiscrContrNoChange" />
<Var Ld="DistributionsAmendNo" />
<Var Ld="MiscAmendYes" />
<Var Ld="NoChangeCompDefinition" />
<Var Ld="NLoans" />
<Var Ld="HCENoChange" />
<Var Ld="NElimOfFamAggreg" />
<Var Ld="AddTransRollNo" />
<Var Ld="PYFYNoChange" />
<Var Ld="ChangeTrustNameYes" />
<Var Ld="ChangedTrustee1Name">Albert Marcus, M.D.</Var>
<Var Ld="ChangedTrustee1EffDate">August 1, 2010</Var>
<Var Ld="ChangedTrustee1Removed" />
<Var Ld="MergFreezeTermNA" />
<Var Ld="NERAdopt" />
<Var Ld="RelDate" />
</answers>
</Project>
答案 0 :(得分:2)
在Visual Studio中打开xml文件,转到“XML”菜单,选择“Create Schema”。
答案 1 :(得分:1)
不使用组,而是将“Var”定义为具有“Ld”属性的元素:
<complexType name="Var">
<annotation>
<documentation>
Description of what a Var is
</documentation>
</annotation>
<attribute name="Ld" type="string">
<annotation>
<documentation>
Description of what this attribute means
</documentation>
</annotation>
</attribute>
</complexType>
定义答案列表:
<complexType name="Answers">
<annotation>
<documentation>
A list of Var elements
</documentation>
</annotation>
<sequence>
<element name="Var" type="Var" minOccurs="0" maxOccurs="unbounded">
<annotation>
<documentation>
The list of Var elements
</documentation>
</annotation>
</element>
</sequence>
</complexType>
然后代替:
<xsd:group ref="Answers"
minOccurs="0"
maxOccurs="unbounded"/>
你要用这个:
<element name="answers" type="Answers"/>
另外,一个好的经验法则是使默认命名空间与您正在编写的文件类型相匹配。因此,如果您正在编写模式,请将其放在根元素中,而不必在任何地方写入“xsd”前缀:
xmlns="http://www.w3.org/2001/XMLSchema"
为您的架构创建目标命名空间也是一个好主意,这样您的元素就会有一个关联的命名空间:
targetNamespace="http://my.example.com/schema"
xmlns:mec="http://my.example.com/schema"
这意味着您的元素将被称为type =“mec:Project”而不仅仅是“Project”,因此在将此模式与另一个模式结合使用时可以防止将来出现任何问题。
答案 2 :(得分:1)
通常,仅包含文本内容的元素类型必须为xs:simpleType
。在这种情况下,这会导致问题,因为可以包含属性(或其他元素)的元素的类型定义必须是xs:complexType
。解决方案是使用xs:simpleContent
仅允许文本,xs:extension
使用所需属性扩展此类型。
xs:simpleContent
用于从其他内置或以前定义的类型派生类型。它要求具有属性xs:extension
的{{1}}或xs:restriction
子元素定义您将扩展或限制的基本类型(简单)。在这种情况下,基本类型可以是base
。 xs:string
或xs:extension
包含所需的新功能。
xs:restriction
<xs:element name="var">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Ld" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
内可以添加几个属性定义 - 在这种情况下,我们只需要一个。 xs:extension
不能包含任何元素定义,只能包含新属性。如果基类型与任何内置模式数据类型不同,例如,如果文本有一些长度限制,则必须将基类型定义为全局简单类型定义,并在{{1}中使用其名称} attribute。
允许包含其他元素的元素内的文本更简单:在定义元素内容时只使用xs:simpleContent
。