A
ALhassen
Guest
Hi all!
I would like to read the nodes in a (big file)xml file via xmlReader and store it to a dictionary, than, I need to check the repetitive nodes and count its number in the xml file one by one, like this:
Let's say we have this xml file:
<root>
<bookstore>
<book>
<title>CSharp<title/>
<Author>Brini AL<Author/>
<Subjet>XML To XSLT<Subject/>
<book/>
<book>
<title>PHP<title/>
<Author>Brini AL<Author/>
<Subjet>XML To XSLT<Subject/>
<book/>
<Person>
<FirstName>AL</FirstName>
<LastName>Brini</LastName></Person>
</bookstore>
</root>
-------I would like to get the next result:
The first repetitive node is :book and its path from the root is : root/bookstore/book and we count 2 nodes
than the second repetitive node is Person and its path is : root/bookstore/ book and we count 1 node
Any help, please? I am a beginner
Thank you in advance.
I try this code:
int nbr = 1;
XmlReader reader = XmlReader.Create(txtXml.Text);
Dictionary<string, int> nodes = new Dictionary<string, int>();
while (reader.Read())
{
nodes.Add(reader.Name, nbr);
reader.MoveToContent();
if ((reader.NodeType==XmlNodeType.EndElement) ||(reader.NodeType != XmlNodeType.Element) || (reader.NodeType == XmlNodeType.Text))
{
reader.Skip();
reader.MoveToContent();
}
MessageBox.Show(reader.Name);//Just for test
}
Continue reading...
I would like to read the nodes in a (big file)xml file via xmlReader and store it to a dictionary, than, I need to check the repetitive nodes and count its number in the xml file one by one, like this:
Let's say we have this xml file:
<root>
<bookstore>
<book>
<title>CSharp<title/>
<Author>Brini AL<Author/>
<Subjet>XML To XSLT<Subject/>
<book/>
<book>
<title>PHP<title/>
<Author>Brini AL<Author/>
<Subjet>XML To XSLT<Subject/>
<book/>
<Person>
<FirstName>AL</FirstName>
<LastName>Brini</LastName></Person>
</bookstore>
</root>
-------I would like to get the next result:
The first repetitive node is :book and its path from the root is : root/bookstore/book and we count 2 nodes
than the second repetitive node is Person and its path is : root/bookstore/ book and we count 1 node
Any help, please? I am a beginner
Thank you in advance.
I try this code:
int nbr = 1;
XmlReader reader = XmlReader.Create(txtXml.Text);
Dictionary<string, int> nodes = new Dictionary<string, int>();
while (reader.Read())
{
nodes.Add(reader.Name, nbr);
reader.MoveToContent();
if ((reader.NodeType==XmlNodeType.EndElement) ||(reader.NodeType != XmlNodeType.Element) || (reader.NodeType == XmlNodeType.Text))
{
reader.Skip();
reader.MoveToContent();
}
MessageBox.Show(reader.Name);//Just for test
}
Continue reading...