Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表达式必须计算为节点集_C#_Xml_Xpath - Fatal编程技术网

C# 表达式必须计算为节点集

C# 表达式必须计算为节点集,c#,xml,xpath,C#,Xml,Xpath,我似乎面临着一个相当复杂的问题(至少对我来说是复杂的)。我们有一个c#程序,它基本上解析模式文件并输出XML。 但现在我的任务是修改这个程序,使它能够添加更多的元素 让我试着解释一下 正如您在下图中所看到的,我有一个模式文件(为了方便起见,只附加了其中的一部分) 突出显示的部分是我所关心的,即USPhone、分机、外国电话。所有三个模式元素都位于Choice模式元素下,而US Phone和Extension位于sequence元素下 目前,对于突出显示的部分,生成的xml如下(以黄色突出显示)

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

让我试着解释一下

正如您在下图中所看到的,我有一个模式文件(为了方便起见,只附加了其中的一部分)

突出显示的部分是我所关心的,即USPhone、分机、外国电话。所有三个模式元素都位于Choice模式元素下,而US Phone和Extension位于sequence元素下

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

然而,我想让这个项目推出这样的东西

i、 e.添加新元素,它是USPhone和Extension的父节点,并将新的e父节点添加到外部电话,这类似于ForeignAddress,它下面有其他元素

当程序递归地遍历每个模式对象并输出xml时,在选择[XmlSchemaChoice]时,我创建了一个新的XMLSchemaElement(USPhoneNumberGrp),它应该充当USPhone和扩展元素的父节点。但是当我尝试使用访问这个新添加的父节点时,问题就出现了

XmlNode parentNode=prototype.SelectSingleNode(路径)

[prototype是一个XMLDocument,到目前为止,它是通过解析所有以前的模式元素创建的]

路径当前有一个值

path=“/PrototypeDocument/CAForm592B/stoppingagent/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>


如果我用
XmlDocument.LoadXml()
加载您问题中的XML,然后用您提供的路径调用
SelectSingleNode(path)
——效果很好,没有例外。您能创建一个复制问题的方法吗?在XSLT中,这种工作要容易得多。。。