I have the following XElement structure:
XElement xmleElement=
<portal>
<form patientid="72615" consentformid="430" appointmentid="386919" actiontype="3">
<signatures>
<signature signatureid="858" encodedsignature="rkJggg==" />
<signature signatureid="859" encodedsignature="" />
</signatures>
</form>
</portal>
Now I want to iterate through this elements each signature and get each encodedsignature XAttribute. Basically want each portal/form/signatures/sugnature[encodedsignature] attribute using some foreach kind of iterator. Any help will be highly appretiated. Thanks in advance.
Sounds like you want something like:
var encodedSignatures = doc.Descendants("signature")
.Select(x => x.Attribute("encodedSignature").Value;
Or to be more explicit about the path:
var encodedSignatures = doc.Root
.Element("form")
.Element("signatures")
.Elements("signature")
.Select(x => x.Attribute("encodedSignature").Value;
In either case, you can then iterate using foreach
- encodedSignatures
will just be an IEnumerable<string>
.
See more on this question at Stackoverflow