我似乎面临着一个非常复杂的问题(至少对我来说很复杂)。我们有c#程序,它基本上解析模式文件并吐出xmls。 但是现在我的任务是修改这个程序,使它能够添加更多的元素。
让我试着解释一下。
如下图所示,我有一个模式文件(为方便起见,只附加了部分文件)。
突出显示的意思是我所关注的,即USPhone,Extension,ForeignPhone。所有三个架构元素都在Choice架构元素下,而US Phone和Extension在序列元素下面。
目前,对于突出显示的部分,生成的xml如下(以黄色突出显示)
但是我希望程序能够输出这样的东西
即。将新元素作为USPhone和Extension的父节点以及新的e父节点添加到Foreign Phone,这类似于ForeignAddress,其下面有其他元素。
当程序以递归方式遍历每个模式对象并吐出xml时,当涉及到Choice [XmlSchemaChoice]时,我创建了一个新的XMLSchemaElement(USPhoneNumberGrp),它应该充当USPhone的父节点和扩展元素。但是当我尝试使用
访问这个新添加的父节点时,就会出现问题XmlNode parentNode = prototype.SelectSingleNode(path);
[prototype是一个XMLDocument,直到现在通过解析所有以前的模式元素而创建]
路径当前具有值
path =" / PrototypeDocument / CAForm592B / WithholdingAgent / USPhoneNumberGrp"
但我收到以下错误"表达式必须评估为节点集"
基本上暗示路径本身是错误的,虽然当我查看到目前为止生成的XMLDocument(见下文)时,我确实看到了新添加的元素USPhoneNumberGrp。
<PrototypeDocument>
<CAForm592B LineNumber="" Description="""" Type="CAForm592BType" Documentation=""CA Form 592-B - Resident and Nonresident Withholding Tax Statement"" ValidValuesForFields="" MaxLengthOfFields="" documentName="CAForm592B">
<Amended MinOccurs="0" LineNumber="Top of Form" Description=""Amended"" Type="BooleanType" Documentation=""Base type for a boolean. Typically used on an Yes or No field."" ValidValuesForFields="" MaxLengthOfFields="" />
<WithholdingAgent LineNumber="Part I" Description=""Withholding agent"" Type="WithholdingAgent" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<Name LineNumber="" Description=""Withholding agent's (payer's/S Corporation/Partnership's/LLC/Trust) name"" Type="CA-BusinessNameType" Documentation=""Type for a Business Name according to CA specifications. Legal Characters: A-Z, a-z, 0-9, hash, hyphen, parentheses, ampersand, apostrophe and single space. Illegal Character: leading space, trailing space, adjacent spaces, and other symbols."" ValidValuesForFields="" MaxLengthOfFields="70" />
<IDNumber LineNumber="" Description=""Identification Number"" Type="IDNumber" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<Individual ChoiceID="b7eaf17b-d515-48b4-b24f-0eb3e136273d" LineNumber="" Description=""Individual identification number"" Type="Individual" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<SSN ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description=""Social Security Number"" Type="SSNType" Documentation=""Type for Social Security No. - 9 digits"" ValidValuesForFields="" MaxLengthOfFields="" />
<ITIN ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description=""IRS Individual Taxpayer Identification Number"" Type="CA-ITINType" Documentation=""CA type for Federal ITIN"" ValidValuesForFields="" MaxLengthOfFields="" />
<NotApplicable ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description=""Not applicable. ID number is individual in type and not applicable per a qualifying reason"" Type="CA-NotApplicableType" Documentation=""CA type for entity ID information to indicate that no Foreign entity Id or CA State Id number applies or exists."" Enum1="Foreign Non-US" Enum2="Applied For" ValidValuesForFields="Foreign Non-US;Applied For" MaxLengthOfFields="" />
</Individual>
<Other ChoiceID="b7eaf17b-d515-48b4-b24f-0eb3e136273d" LineNumber="" Description=""Other business or non-individual identification number"" Type="CA-BusinessIdType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<CACorporationNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description=""California corporation number"" Type="CA-CorporationNumberType" Documentation=""Type for California corporation number"" ValidValuesForFields="" MaxLengthOfFields="" />
<SOSNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description=""California Secretary of State number"" Type="CA-SOSNType" Documentation=""Type for California Secretary of State file number"" ValidValuesForFields="" MaxLengthOfFields="" />
<LLCTempNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description=""Limited Liability Company temporary number"" Type="CA-LLCTempNumberType" Documentation=""CA type for LLC Temporary Number assigned by FTB"" ValidValuesForFields="" MaxLengthOfFields="" />
<NotApplicable ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description=""Not Applicable per qualifying reason"" Type="CA-NotApplicableType" Documentation=""CA type for entity ID information to indicate that no Foreign entity Id or CA State Id number applies or exists."" Enum1="Foreign Non-US" Enum2="Applied For" ValidValuesForFields="Foreign Non-US;Applied For" MaxLengthOfFields="" />
<FEIN ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description=""Federal employee identification number"" Type="EINType" Documentation=""Type for Employer Identification No. - 9 digits"" ValidValuesForFields="" MaxLengthOfFields="" />
</Other>
</IDNumber>
<USAddress ChoiceID="f97d374d-0961-4101-bdd0-85099615eb54" LineNumber="" Description=""United States Address"" Type="USAddressType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<AddressLine1Txt LineNumber="" Description="""" Type="StreetAddressType" Documentation=""Address line 1"" ValidValuesForFields="" MaxLengthOfFields="35" />
<AddressLine2Txt MinOccurs="0" LineNumber="" Description="""" Type="StreetAddressType" Documentation=""Address line 2"" ValidValuesForFields="" MaxLengthOfFields="35" />
<CityNm LineNumber="" Description="""" Type="CityType" Documentation=""City"" ValidValuesForFields="" MaxLengthOfFields="22" />
<StateAbbreviationCd LineNumber="" Description="""" Type="StateType" Documentation=""State"" Enum1="AL" Enum2="AK" Enum3="AS" Enum4="AZ" Enum5="AR" Enum6="CA" Enum7="CO" Enum8="MP" Enum9="CT" Enum10="DE" Enum11="DC" Enum12="FM" Enum13="FL" Enum14="GA" Enum15="GU" Enum16="HI" Enum17="ID" Enum18="IL" Enum19="IN" Enum20="IA" Enum21="KS" Enum22="KY" Enum23="LA" Enum24="ME" Enum25="MH" Enum26="MD" Enum27="MA" Enum28="MI" Enum29="MN" Enum30="MS" Enum31="MO" Enum32="MT" Enum33="NE" Enum34="NV" Enum35="NH" Enum36="NJ" Enum37="NM" Enum38="NY" Enum39="NC" Enum40="ND" Enum41="OH" Enum42="OK" Enum43="OR" Enum44="PW" Enum45="PA" Enum46="PR" Enum47="RI" Enum48="SC" Enum49="SD" Enum50="TN" Enum51="TX" Enum52="VI" Enum53="UT" Enum54="VT" Enum55="VA" Enum56="WA" Enum57="WV" Enum58="WI" Enum59="WY" Enum60="AA" Enum61="AE" Enum62="AP" ValidValuesForFields="See instructions for valid values" MaxLengthOfFields="" />
<ZIPCd LineNumber="" Description="""" Type="ZIPCodeType" Documentation=""ZIP code"" ValidValuesForFields="" MaxLengthOfFields="" />
</USAddress>
<ForeignAddress ChoiceID="f97d374d-0961-4101-bdd0-85099615eb54" LineNumber="" Description=""Foreign Address"" Type="CA-ForeignAddressType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<StreetAddress LineNumber="" Description=""Address line 1"" Type="CA-StreetAddressType" Documentation=""Type for a Street Address according to CA specifications"" ValidValuesForFields="" MaxLengthOfFields="" /><InCareOfAddress MinOccurs="0" LineNumber="" Description=""Address line 2"" Type="CA-StreetAddressType" Documentation=""Type for a Street Address according to CA specifications"" ValidValuesForFields="" MaxLengthOfFields="" />
<City MinOccurs="0" LineNumber="" Description=""City"" Type="TextType" Documentation=""Used for a text field. Legal Characters: printable characters from ! to ~ plus symbols from ¡ to ¿ plus Spanish characters and single space. Illegal Character: leading space, trailing space, adjacent spaces."" ValidValuesForFields="" MaxLengthOfFields="50" />
<Country LineNumber="" Description=""Country"" Type="CA-CountryType" Documentation=""CA type for foreign address country which may include province and/or state"" ValidValuesForFields="" MaxLengthOfFields="19" />
</ForeignAddress>
<USPhoneNumberGrp ChoiceID="2d3ce0ab-bc99-465f-a80c-b70dd0c9ebff" LineNumber="" Description="""" Type="" Documentation="" ValidValuesForFields="" MaxLengthOfFields="" />
</WithholdingAgent>
</CAForm592B>
</PrototypeDocument>
我不确定我错误地得到了这个错误。
我希望你们能在这里帮助我。
谢谢, AJ