Solved

XML data into comma seperated string

Posted on 2009-04-08
5
295 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
ID: 24098668
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
ID: 24098731
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
ID: 24098933
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
ID: 24100500
What I am getting is 8834,8834

While is should be 7369,8834.
0
 

Author Comment

by:immtrac
ID: 24100818
Never mind. I got it.

Thanks for ur help
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

932 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

8 Experts available now in Live!

Get 1:1 Help Now