Solved

xml doubt

Posted on 2006-10-31
6
180 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…
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 …

705 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