Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 5th, 2007, 01:55 AM
ahmed.maryam@gmail.com
Guest
 
Posts: n/a
Default Storing EndElements as XmlNodes

Hi Everyone,

How can I check for end elements in a XmlNodeList that consists of all
the children nodes in my XML document?
Can I avoid using XmlReader or XPath Navigator? Thanks for any help!

I'm using Visual Studio 2005 and my application is in C#.

  #2  
Old March 5th, 2007, 04:45 AM
Bjoern Hoehrmann
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

* ahmed.maryam@gmail.com wrote in microsoft.public.dotnet.xml:
Quote:
>How can I check for end elements in a XmlNodeList that consists of all
>the children nodes in my XML document?
>Can I avoid using XmlReader or XPath Navigator? Thanks for any help!
How did this XmlNodeList came to be? Generally it cannot include End-
Element nodes, they are an artificial node type for use with sequential
processors, the document object model does not store them, they are
implied by the parent/child relationships stored in it.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
  #3  
Old March 5th, 2007, 05:45 AM
ahmed.maryam@gmail.com
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

Hi Bjoern!

Thanks for your reply (on two forums!), I was afraid that might be the
case. My XmlNodeList is created in a recursive loop that saves all the
child nodes at any given node in the XmlDocument. Take a look:

// This function writes the name of every element it encounters to a
textbox on the C# form

private void findElements( XmlNode parent )
{

if (parent.Name.Equals("book")) //All element names with book in my
xml document
{

userLog.Text += ("The name of your book is" +
parent.Attributes[0].Value ); //write to textbox

}

if (parentNode.HasChildNodes) //Only do recursion if there are child
nodes left
{
XmlNodeList nodelist = parent.ChildNodes; //store all
child nodes in a list

foreach (XmlNode node in nodelist) //for each child in
the list
{

drawTree(node); //recursively iterate through the
element names

}
}
}

The problem is (as you already know) that when I read in the names, I
only know where the nodes start, but if I wanted to print out the
names of the closing tags (end elements), I can see no way to access
them.

I guess my best bet is to either change my structure to use XmlReader
or use XPath navigator to access the end elements. All I want to do is
print them the screen. Is there an equivalent to XmlNodeList in
XmlReader?

Thanks for your help!!







  #4  
Old March 5th, 2007, 07:45 AM
ahmed.maryam@gmail.com
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

Hi Bjoern!

Thanks for your reply (on two forums!), I was afraid that might be the
case. My XmlNodeList is created in a recursive loop that saves all the
child nodes at any given node in the XmlDocument. Take a look:

// This function writes the name of every element it encounters to a
//textbox on the C# form

private void findElements( XmlNode parent )
{

if (parent.Name.Equals("book")) //All element names with book in my
//xml document
{

userLog.Text += ("The name of your book is" +
parent.Attributes[0].Value ); //write to
textbox

}


if (parentNode.HasChildNodes) //Only do recursion if there are
child
// nodes left
{
XmlNodeList nodelist = parent.ChildNodes; //store all
child
//
nodes in a list

foreach (XmlNode node in nodelist) //for each child in
//
the list
{

findElements(node); //recursively iterate through
the
//element names

}
}

}

The problem is (as you already know) that when I read in the names, I
only know where the nodes start, but if I wanted to print out the
names of the closing tags (end elements), I can see no way to access
them.

I guess my best bet is to either change my structure to use XmlReader
or use XPath navigator to access the end elements. All I want to do is
print them the screen. Is there an equivalent to XmlNodeList in
XmlReader?

Thanks for your help!!

  #5  
Old March 5th, 2007, 08:25 AM
ahmed.maryam@gmail.com
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

Hi Bjoern!

Thanks for your reply (on two forums!), I was afraid that might be the
case. My XmlNodeList is created in a recursive loop that saves all the
child nodes at any given node in the XmlDocument. Take a look:

// This function writes the name of every element it encounters to a
//textbox on the C# form

private void findElements( XmlNode node )
{

if (node.Name.Equals("book"))
{
userLog.Text += ("The name of your book is" +
parent.Attributes[0].Value );

}

if (node.HasChildNodes)

{
XmlNodeList nodelist = node.ChildNodes;

foreach (XmlNode child in nodelist)
{

findElements(child); //recursion

}
}

}

The problem is (as you already know) that when I read in the names, I
only know where the nodes start, but if I wanted to print out the
names of the closing tags (end elements), I can see no way to access
them.

I guess my best bet is to either change my structure to use XmlReader
or use XPath navigator to access the end elements. All I want to do is
print them the screen. Is there an equivalent to XmlNodeList in
XmlReader?

Thanks for your help!!

  #6  
Old March 5th, 2007, 07:05 PM
John Saunders
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

<ahmed.maryam@gmail.comwrote in message
news:1173072969.090939.288920@64g2000cwx.googlegro ups.com...
Quote:
Hi Bjoern!
>
Thanks for your reply (on two forums!), I was afraid that might be the
case. My XmlNodeList is created in a recursive loop that saves all the
child nodes at any given node in the XmlDocument. Take a look:
>
// This function writes the name of every element it encounters to a
textbox on the C# form
....
Quote:
The problem is (as you already know) that when I read in the names, I
only know where the nodes start, but if I wanted to print out the
names of the closing tags (end elements), I can see no way to access
them.
The names of the end tags are the same as the names of the start tags.

John


  #7  
Old March 5th, 2007, 08:27 PM
ahmed.maryam@gmail.com
Guest
 
Posts: n/a
Default Re: Storing EndElements as XmlNodes

>
Quote:
The names of the end tags are the same as the names of the start tags.
>
John
Hi John,

YES! I figured that out this morning as well but thanks for the reply!
It turns out all I had to do was look for the name again after the
recursive loop and close each tag! Why is that the answer with XML is
always way easier than whatever I'm thinking? hehe.

Thanks!



 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles