Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hello!

This is my XML:

<break>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<p><page num="5/>This is a paragraph.</p>
<h3>This is a h3 tag.</h3>
<p>This is a paragraph.</p>
<h4><page num="6/>This is a h4 tag.</h4>
<h4>This is a h4 tag.</h4>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
<h5><page num="7/>This is a h5 tag</h5>
</break>


Here, the element <page> is present 3 times in the same <break> element. I want to get all the <page> nodes in a list but I am not getting it as the tree is different for each <page>. How do I get it?

Please help.

Regards
Aman

What I have tried:

C#
var breakelement = xdoc.Elements("break").Descendants().ToList();
Posted
Updated 26-Jan-19 9:25am
Comments
Richard MacCutchan 26-Jan-19 4:55am    
What items do you get in your list? Looking at your data I would think you need to go to every descendant of "break" and search through the tree for "page" items.
Primo Chalice 26-Jan-19 5:44am    
Hello!

I am only getting the first occurrence of <page>. So do I have to do it in another way? Please tell me where do I need to change.

Regards
Aman
F-ES Sitecore 26-Jan-19 6:38am    
What is "xdoc"? How can we help you if we don't even know what classes you are using?

1 solution

Your XML is "mal-formed"; the double quotes are out of place / missing.

<p><page num="5/>This is a paragraph.</p>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900