Solved

xml doubt

Posted on 2006-10-31
6
176 Views
Last Modified: 2013-11-19
<BP>
      <Data>
            <PS>
            <script>000102</script>
            <script>000203</script>
            </PS>
      <Data>
</BP>

I want to find the count of the script tag in this xml file. I want the first script as
as separate and second script as seperate.

but if i give

xmldoc.GetElementsByTagName("Script").Item(0).InnerText

it gives full value as 000101000203 but i want it as separate?
0
Comment
Question by:Rahamathulla_J
  • 4
  • 2
6 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17842456
works fine for me...here's my version of your code :

using System;
using System.Xml;

class MyClass{

      public static void Main(string[] args){

            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<BP><Data><PS><script>000102</script><script>000203</script></PS></Data></BP>");
            System.Console.WriteLine(doc.GetElementsByTagName("script").Item(0).InnerText);
      }
}

The output of this code is : 000102

I assume you know that you have a couple of errors in yours :

<Data> element is not closed properly. Missing / in end tag.
You are looking for elements with a tag name of "Script". There aren't any, it's "script".
0
 

Author Comment

by:Rahamathulla_J
ID: 17847942
yes i had some error in the xml document. Now i correct it.

One more doubt u get tje output

 000102

because of ---------------> doc.GetElementsByTagName("script").Item(0).InnerText

How can i get the next value i mean 000203
0
 

Author Comment

by:Rahamathulla_J
ID: 17847952

Or if i have n number of script tags i have to loop through all the script tags and read the corresponding value and store it in arraylist this is my specific requirement. please help me.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 15

Accepted Solution

by:
ozymandias earned 250 total points
ID: 17848121
using System;
using System.Xml;

class MyClass{

     public static void Main(string[] args){

          ListArray list = new ListArray();
          XmlDocument doc = new XmlDocument();
          doc.LoadXml("<BP><Data><PS><script>000102</script><script>000203</script></PS></Data></BP>");
          foreach(XmlElement e in doc.GetElementsByTagName("script")){
                    Console.WriteLine("adding " + e.InnerText );
                    list.Add(e.InnerText);
          }
     }
}
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17902725
Hi, did this answer your question ?
0
 
LVL 15

Expert Comment

by:ozymandias
ID: 17912909
How is this a Grade B ?
Not only did I answer your questoin I actually provided working code to do it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now