tags:

views:

1036

answers:

4

Sample XML

<A>
   <B>
      <B1/>

      <B2/>
      <B3/>
      <B4/>
      <B5/>
   </B>
   <C>
      <C1/>
      <C2/>
      <C3/>
      <C4/>
      <C5/>
   </C>
</A>

Query: C# When I read the the child nodes of A it retuns nodes B & C with their child nodes.

Is there any possibility so that I can get only B & C without their respective child nodes

I need to populate the tree with this type of xml & the xml file is quite big. so I need to load the childs at the time of expanding any node

Requirement is Suppose I try to expand A node the I want only B & C,

If I expand B then I want B1 to B5

+1  A: 

if you use java, you can implement a SAX Handler building your DOM and ignoring the children.

Pierre
-1: If I had a pony...
Not Sure
FYI he changed the question a lot. THis was correct answer for the first version of question. ;-)
Shoban
So I see...you can have your point back :)
Not Sure
+1  A: 

It's a badly worded question so I'm not entirely sure what you are trying to do but if you just want all the child nodes of the root (A) then use an XmlDocument with XPath like this:

XmlDocument doc = new XmlDocument();
doc.Load(xmlFile);
XmlNodeList nodes = doc.SelectNodes("/A/*");
foreach(XmlNode node in nodes){
   //DO STUFF
}
Russell Troywest
Sorry, that still loads the entire XML document into memory. See foreachdev's answer.
Not Sure
Yes, I almost mentioned XmlReader but the question was not worded very well so it was rather difficult to know what they wanted.
Russell Troywest
+3  A: 

Use a XmlReader. XmlDocument by design has to load the whole Xml document into memory.

foreachdev
+1 for the correct answer
Not Sure
A: 

if i understand the question right, u need to get children of the node without getting their children. this can be done by xquery (child::*)

so if u apply it in A node it will give B and C. if u apply it in B then it will give B1-B5.

spectator