Solved

XML data into comma seperated string

Posted on 2009-04-08
5
290 Views
Last Modified: 2012-05-06
I call a web service and get following XML (see code).

I need to know how do I convert the data into:

7369, 8834

In other words, If I get results, I need to convert result into comma separated string so that I can pass it to query string in URL



- <NewDataSet>

- <Table>

  <ext_user_id>7369</ext_user_id> 

  </Table>

- <Table>

  <ext_user_id>8834</ext_user_id> 

  </Table>

  </NewDataSet>

Open in new window

0
Comment
Question by:immtrac
  • 3
  • 2
5 Comments
 
LVL 23

Accepted Solution

by:
apresto earned 125 total points
Comment Utility
Something like this?
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();

        doc.LoadXml("<NewDataSet><Table><ext_user_id>7369</ext_user_id></Table><Table><ext_user_id>8834</ext_user_id></Table></NewDataSet>");

        System.Xml.XmlNodeList nodeList = doc.GetElementsByTagName("Table");
 

        string values = "";
 

        foreach (System.Xml.XmlNode tableNode in nodeList)

        {

            System.Xml.XmlNode numNode = tableNode.SelectSingleNode("ext_user_id");

            values = numNode.InnerText + ",";

        }

        values += values.Substring(0, values.Length - 1);

Open in new window

0
 

Author Comment

by:immtrac
Comment Utility
Thanks for your reply. When I call web service  I don't know if I get 10 ids, 100 ids or nothing.

So I can not  hard code the XML.

Also is there way that we can use split() function?
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
I was only hardcoding the xml for demonstration purposes, all you need to do is put the string returned by the webservice into it. This method will work for 10 or 100 nodes in an xml string.
Why would you want to use split, the XmlDocument class is there for a reason, lol
0
 

Author Comment

by:immtrac
Comment Utility
What I am getting is 8834,8834

While is should be 7369,8834.
0
 

Author Comment

by:immtrac
Comment Utility
Never mind. I got it.

Thanks for ur help
0

Featured Post

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!

Join & Write a Comment

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

16 Experts available now in Live!

Get 1:1 Help Now