Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/336.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#:使用Linq在另一个元素之前获取特定元素_C#_Linq To Xml_Xelement_Xattribute_Linq To Xsd - Fatal编程技术网

C#:使用Linq在另一个元素之前获取特定元素

C#:使用Linq在另一个元素之前获取特定元素,c#,linq-to-xml,xelement,xattribute,linq-to-xsd,C#,Linq To Xml,Xelement,Xattribute,Linq To Xsd,考虑来自XSD的以下代码段: <xs:complexType name="AccountIdentification4ChoiceGPS"> <xs:choice> <xs:element name="IBAN" type="IBAN2007Identifier"> <xs:annotation> <xs:appinfo>

考虑来自XSD的以下代码段:

    <xs:complexType name="AccountIdentification4ChoiceGPS">
    <xs:choice>
        <xs:element name="IBAN" type="IBAN2007Identifier">
            <xs:annotation>
                <xs:appinfo>
                    <xs:logicalname>IBAN</xs:logicalname>
                    <xs:additionalInfo>[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}</xs:additionalInfo>
                    <xs:ISOType>(CashAccount20)</xs:ISOType>
                </xs:appinfo>
                <xs:documentation>Unambiguous identification of the account as International Bank Account Number (IBAN).</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="Othr" type="GenericAccountIdentification1GPS">
            <xs:annotation>
                <xs:appinfo>
                    <xs:logicalname>Other</xs:logicalname>
                    <xs:ISOType>(CashAccount20)</xs:ISOType>
                </xs:appinfo>
            </xs:annotation>
        </xs:element>
    </xs:choice>
</xs:complexType>
这就是我被卡住的地方。

试试:

IEnumerable<XElement> elementAbove = xsdDocument.Descendants()
   .Where(x => x.Name.LocalName == "complexType" && x.Descendants().Any(y => y.Name.LocalName == "element" && y.Attributes().Any(z => z.Value == "IBAN")));
IEnumerable elementOver=xsdDocument.subjections()
其中(x=>x.Name.LocalName==“complexType”&&x.substands().Any(y=>y.Name.LocalName==“element”&&y.Attributes().Any(z=>z.Value==“IBAN”));
试试:

IEnumerable elementOver=xsdDocument.subjections()
其中(x=>x.Name.LocalName==“complexType”&&x.substands().Any(y=>y.Name.LocalName==“element”&&y.Attributes().Any(z=>z.Value==“IBAN”));

这几乎成功了。
z.Name
应该是
z.Value
。谢谢你,马特!这几乎成功了。
z.Name
应该是
z.Value
。谢谢你,马特!
IEnumerable<XElement> elementAbove = xsdDocument.Descendants()
   .Where(x => x.Name.LocalName == "complexType" && x.Descendants().Any(y => y.Name.LocalName == "element" && y.Attributes().Any(z => z.Value == "IBAN")));