Solved

xml doubt

Posted on 2006-10-31
6
175 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

758 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

22 Experts available now in Live!

Get 1:1 Help Now