سؤال

For an XElement like

<a>
 <b><c id="2"></b>
 <b><c id="3"></b>
 <b><c id="1"></b>
</a>

Is there a way to get a list of <b> ordered by <c> id values?

I unsuccessfully tried

bElements.OrderBy(function b As XElement) b.Elements.Attributes("id")) and bElements.OrderBy(function b As XElement) b.Elements.ToString).

هل كانت مفيدة؟

المحلول

Depending on your precise needs, you could do this:

bElements.OrderBy(function (b As XElement) b.Elements.Attributes("id").First().Value)

Or this:

bElements.OrderBy(function (b As XElement) b.Elements.First().Attribute("id").Value)

Or even this:

bElements.OrderBy(function (b As XElement) b.<c>.@id)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top