C#:使用Linq在另一个元素之前获取特定元素
考虑来自XSD的以下代码段: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>
<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")));