表达式必须求值为节点集

时间:2015-04-22 23:01:27

标签: c# xml xpath

我似乎面临着一个非常复杂的问题(至少对我来说很复杂)。我们有c#程序,它基本上解析模式文件并吐出xmls。 但是现在我的任务是修改这个程序,使它能够添加更多的元素。

让我试着解释一下。

如下图所示,我有一个模式文件(为方便起见,只附加了部分文件)。

Schema File

突出显示的意思是我所关注的,即USPhone,Extension,ForeignPhone。所有三个架构元素都在Choice架构元素下,而US Phone和Extension在序列元素下面。

目前,对于突出显示的部分,生成的xml如下(以黄色突出显示)

Current XML Output

但是我希望程序能够输出这样的东西

Modified XmL Output

即。将新元素作为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="&quot;&quot;" Type="CAForm592BType" Documentation="&quot;CA Form 592-B - Resident and Nonresident Withholding Tax Statement&quot;" ValidValuesForFields="" MaxLengthOfFields="" documentName="CAForm592B">
<Amended MinOccurs="0" LineNumber="Top of Form" Description="&quot;Amended&quot;" Type="BooleanType" Documentation="&quot;Base type for a boolean. Typically used on an Yes or No field.&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<WithholdingAgent LineNumber="Part I" Description="&quot;Withholding agent&quot;" Type="WithholdingAgent" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<Name LineNumber="" Description="&quot;Withholding agent's (payer's/S Corporation/Partnership's/LLC/Trust) name&quot;" Type="CA-BusinessNameType" Documentation="&quot;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.&quot;" ValidValuesForFields="" MaxLengthOfFields="70" />
<IDNumber LineNumber="" Description="&quot;Identification Number&quot;" Type="IDNumber" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<Individual ChoiceID="b7eaf17b-d515-48b4-b24f-0eb3e136273d" LineNumber="" Description="&quot;Individual identification number&quot;" Type="Individual" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<SSN ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description="&quot;Social Security Number&quot;" Type="SSNType" Documentation="&quot;Type for Social Security No. - 9 digits&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<ITIN ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description="&quot;IRS Individual  Taxpayer Identification Number&quot;" Type="CA-ITINType" Documentation="&quot;CA type for Federal ITIN&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<NotApplicable ChoiceID="746e28ef-3a82-4de6-b7d1-09a336474669" LineNumber="" Description="&quot;Not applicable. ID number is individual in type and not applicable per a qualifying reason&quot;" Type="CA-NotApplicableType" Documentation="&quot;CA type for entity ID information to indicate that no Foreign entity Id or CA State Id number applies or exists.&quot;" Enum1="Foreign Non-US" Enum2="Applied For" ValidValuesForFields="Foreign Non-US;Applied For" MaxLengthOfFields="" />
</Individual>
<Other ChoiceID="b7eaf17b-d515-48b4-b24f-0eb3e136273d" LineNumber="" Description="&quot;Other business or non-individual identification number&quot;" Type="CA-BusinessIdType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<CACorporationNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description="&quot;California corporation number&quot;" Type="CA-CorporationNumberType" Documentation="&quot;Type for California corporation number&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<SOSNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description="&quot;California Secretary of State number&quot;" Type="CA-SOSNType" Documentation="&quot;Type for California Secretary of State file number&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<LLCTempNumber ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description="&quot;Limited Liability Company temporary number&quot;" Type="CA-LLCTempNumberType" Documentation="&quot;CA type for LLC Temporary Number assigned by FTB&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<NotApplicable ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description="&quot;Not Applicable per qualifying reason&quot;" Type="CA-NotApplicableType" Documentation="&quot;CA type for entity ID information to indicate that no Foreign entity Id or CA State Id number applies or exists.&quot;" Enum1="Foreign Non-US" Enum2="Applied For" ValidValuesForFields="Foreign Non-US;Applied For" MaxLengthOfFields="" />
<FEIN ChoiceID="87b268af-3e7a-4fd2-9cff-c2547f34ec17" LineNumber="" Description="&quot;Federal employee identification number&quot;" Type="EINType" Documentation="&quot;Type for Employer Identification No. - 9 digits&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
</Other>
</IDNumber>
<USAddress ChoiceID="f97d374d-0961-4101-bdd0-85099615eb54" LineNumber="" Description="&quot;United States Address&quot;" Type="USAddressType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<AddressLine1Txt LineNumber="" Description="&quot;&quot;" Type="StreetAddressType" Documentation="&quot;Address line 1&quot;" ValidValuesForFields="" MaxLengthOfFields="35" />
<AddressLine2Txt MinOccurs="0" LineNumber="" Description="&quot;&quot;" Type="StreetAddressType" Documentation="&quot;Address line 2&quot;" ValidValuesForFields="" MaxLengthOfFields="35" />
<CityNm LineNumber="" Description="&quot;&quot;" Type="CityType" Documentation="&quot;City&quot;" ValidValuesForFields="" MaxLengthOfFields="22" />
<StateAbbreviationCd LineNumber="" Description="&quot;&quot;" Type="StateType" Documentation="&quot;State&quot;" 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="&quot;&quot;" Type="ZIPCodeType" Documentation="&quot;ZIP code&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
</USAddress>
<ForeignAddress ChoiceID="f97d374d-0961-4101-bdd0-85099615eb54" LineNumber="" Description="&quot;Foreign Address&quot;" Type="CA-ForeignAddressType" Documentation="" ValidValuesForFields="" MaxLengthOfFields="">
<StreetAddress LineNumber="" Description="&quot;Address line 1&quot;" Type="CA-StreetAddressType" Documentation="&quot;Type for a Street Address according to CA specifications&quot;" ValidValuesForFields="" MaxLengthOfFields="" /><InCareOfAddress MinOccurs="0" LineNumber="" Description="&quot;Address line 2&quot;" Type="CA-StreetAddressType" Documentation="&quot;Type for a Street Address according to CA specifications&quot;" ValidValuesForFields="" MaxLengthOfFields="" />
<City MinOccurs="0" LineNumber="" Description="&quot;City&quot;" Type="TextType" Documentation="&quot;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.&quot;" ValidValuesForFields="" MaxLengthOfFields="50" />
<Country LineNumber="" Description="&quot;Country&quot;" Type="CA-CountryType" Documentation="&quot;CA type for foreign address country which may include province and/or state&quot;" ValidValuesForFields="" MaxLengthOfFields="19" />
</ForeignAddress>
<USPhoneNumberGrp ChoiceID="2d3ce0ab-bc99-465f-a80c-b70dd0c9ebff" LineNumber="" Description="&quot;&quot;" Type="" Documentation="" ValidValuesForFields="" MaxLengthOfFields="" />
</WithholdingAgent>
</CAForm592B>
</PrototypeDocument>

我不确定我错误地得到了这个错误。

我希望你们能在这里帮助我。

谢谢, AJ

0 个答案:

没有答案