Solved

XML data into comma seperated string

Posted on 2009-04-08
5
298 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

808 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