Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

xml doubt

Posted on 2006-10-31
6
Medium Priority
?
184 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
ozymandias earned 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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 …
Suggested Courses

618 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