Solved

xml doubt

Posted on 2006-10-31
6
179 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

726 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