Display XML in .aspx page

I am returned an xmlnode from a web service.  I would like to display the xml string that is in the xmlnode.innerstring. The value in the xmlnode.innerstring is below.

<Course CourseID="17" CourseName="Human Performance Tools - Self Checking" /><Course CourseID="68" CourseName="Human Performance Tools - 3 Way Communication" /><Course CourseID="11" CourseName="Human Performance Tools - Phonetic Alphabet" /><Course CourseID="10" CourseName="Human Performance Tools - Pre-Job Briefing" />
DotNetNoobyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

F IgorDeveloperCommented:
You need to encode the XML content as HTML:



Dim encoded As New System.IO.StringWriter
Server.HtmlEncode(xmlnode.innerstring, encoded)

//encoded.ToString has the "HTML Encoded" XML source
Response.Write(encoded.ToString)

DotNetNoobyAuthor Commented:
That displays everything.  What is the best way to format it so its easier to read?
jphiferCommented:
Are you trying to just get out the CourseID and CourseName from each child node?
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

DotNetNoobyAuthor Commented:
yes
jphiferCommented:
What's the parent node name?
DotNetNoobyAuthor Commented:
myNode
jphiferCommented:
First, place a literal on the page: <asp:Literal id="_ltCourses" runat="server" />

Then add this code in the .cs file.

System.IO.Stream    stream = response.GetResponseStream();
XmlDocument      xml = new XmlDocument();
xml.Load(stream);

XmlNode      node = xml.SelectSingleNode("descendant::myNode");
      if (node != null)
      {
            XmlNodeList      courses = node.SelectNodes("descendant::Course");
            if (courses != null)
            {
                    foreach (XmlNode      course in courses)
                  {
                        string course_id = course.Attributes["CourseID"].Value;
                        string course_name = course.Attributes["CourseName"].Value;

                        _ltCourses.Text += string.format("CourseID: {0}<br />CourseName: {1}",course_id,course_name);
                  }
            }
      }
DotNetNoobyAuthor Commented:
Its telling me getResponseStream is not a member of system.web.HttpResponse
jphiferCommented:
How are you getting the response back from the web service? In other words, what's the object you are using?
DotNetNoobyAuthor Commented:
Dim node As XmlNode = ws.GetCourses()
jphiferCommented:
Oh, well in that case, you're already getting back an XML Node, so all you need is this:

XmlNode      node = ws.GetCourses();
      if (node != null)
      {
            XmlNodeList      courses = node.SelectNodes("descendant::Course");
            if (courses != null)
            {
                    foreach (XmlNode      course in courses)
                  {
                        string course_id = course.Attributes["CourseID"].Value;
                        string course_name = course.Attributes["CourseName"].Value;

                        _ltCourses.Text += string.format("CourseID: {0}<br />CourseName: {1}",course_id,course_name);
                  }
            }
      }

Sorry for not being VB.Net. =)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DotNetNoobyAuthor Commented:
Solved
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.