Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / September 2004

Tip: Looking for answers? Try searching our database.

Read complex XML into a dataset or XMLDeSerializer

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Shailendra Batham - 27 Sep 2004 19:25 GMT
hey xml gurus
I have a xml which is as follows, so my question is how can I read this
XML is VB.Net or C#. I want to loop for every survey ID and insider
every survey I want to loop for each user ID and get their values.

<?xml version="1.0" encoding="utf-8"?>
<UserData>
 <Survey ID="S1">
   <User ID="U1">
     <EmailAddress>u1@ss.com</EmailAddress>
   </User>
   <User ID="U2">
    <EmailAddress>u2@ss.com</EmailAddress>
   </User>
 </Survey>
 <Survey ID="S2">
   <User ID="U4">
     <EmailAddress>u4@ss.com</EmailAddress>
   </User>
 </Survey>
</UserData>

thanks,
shailendra
Victor Hadianto - 28 Sep 2004 01:10 GMT
Well there are many ways of doing this, you can use XmlReader to read the
XML doc or you can use XPath to get the nodes that you want. Depending on
the your situation you should choose the one that suit you best.

XPath is the most convenient - imho, so I would do:

XmlNodeList surveyList = xmlDoc.SelectNodes("//UserData/Survey");
foreach (XmlNode surveyNode in surveyList)
{
   Console.WriteLine(surveyNode.Attributes["ID"].InnerText);
   XmlNodeList userList = surveyNode.SelectNodes("User");
   foreach (XmlNode userNode in userList)
   {
       Console.WriteLine(" " + userNode.Attributes["ID"].InnerText);
   }
}

---
Victor Hadianto
http://www.synop.com/Products/SauceReader/

> hey xml gurus
> I have a xml which is as follows, so my question is how can I read this
[quoted text clipped - 20 lines]
> thanks,
> shailendra

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.