Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

XML Child Nodes

Posted on 2009-05-14
7
Medium Priority
?
450 Views
Last Modified: 2012-05-07
How do I output xml data and all child nodes in a repeater or labels?
0
Comment
Question by:lrbrister
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Expert Comment

by:RamanaChoudary
ID: 24386151
Private Shared xmlDoc As XmlDocument          
 xmlDoc = New XmlDocument
            xmlDoc.Load(FilePath)

 For Each EnumDll In xmlDoc.ChildNodes.Item(1).ChildNodes 'root node

     For Each xmlNodeitem As XmlNode In EnumDll.ChildNodes 'child Nodes
          Label1.Text = CType(xmlNodeitem.ChildNodes.Item(2).InnerText, String)
     Next'child node

Next


try above code

0
 

Author Comment

by:lrbrister
ID: 24386362
RamanaChoudary:
How would I reference a dataset?

I have the data in a dataset which I've been parsing out with hard coded node lists...which I absolutely do not want to do...

Please see the code AND the actual XML below


------Dataset Code That has been getting "node list" for different repeaters-------
blah...blah...blah...
Session("response").WriteXml(xmlTextWriter, XmlWriteMode.IgnoreSchema)
 
        ' Write the Xml out to a string   
        Dim contentAsXmlString As String = stringWriter.ToString()
 
        ' load the string of Xml into the document   
        xmlDocument.LoadXml(contentAsXmlString)
 
        ' parse out the session token 
        Dim _response As XmlNodeList = xmlDocument.SelectNodes("//responseEnvelope/responseHeader/statusData")
        Dim _response2 As XmlNodeList = xmlDocument.SelectNodes("//responseEnvelope/ReservationResponse/ReservationToken")
 
        Dim _response3 As XmlNodeList = xmlDocument.SelectNodes("//responseEnvelope/ReservationResponse")
Dim _response2 As XmlNodeList = xmlDocument.SelectNodes("//responseEnvelope/ReservationResponse/ReservationToken")
 
        Dim _response3 As XmlNodeList = xmlDocument.SelectNodes("//responseEnvelope/ReservationResponse")
 
 
 
        hdr.DataSource = _response
        hdr.DataBind()
 
        hdr2.DataSource = _response2
        hdr2.DataBind()
 
        hdr3.DataSource = _response3
        hdr3.DataBind()
 
 
---ACTUAL DATA------
<?xml version="1.0"?>
<responseEnvelope>
    <responseHeader>
        <statusData>
            <completionCode>0</completionCode>
            <completionMessage>Request Completed Successfully.</completionMessage>
        </statusData>
    </responseHeader>
    <ReservationResponse>
        <ReservationToken>
            <inventoryType>1</inventoryType>
            <referenceNumber>73510000113587001</referenceNumber>
            <unitNumber>1856</unitNumber>
        </ReservationToken>
        <status>C</status>
    </ReservationResponse>
</responseEnvelope>

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1200 total points
ID: 24386420
So first you are writing data from dataset to xml and then you want to use that xml to populate labels or repeater? Why not use the dataset directly?

lblTest.Text = dSet.Tables(0).Rows(0).item("Name")
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Assisted Solution

by:channa_m
channa_m earned 800 total points
ID: 24386429
follow this example
// Sample 
<?xml version="1.0"?>
<library>
	<book>
		<title> Book1 </title>
		<author> Author1 </author>
		<isbn> isbn1 </isbn>
	</book>
	<book>
		<title> Book2 </title>
		<author> Author2 </author>
		<isbn> isbn2 </isbn>
	</book>
	<book>
		<title> Book3 </title>
		<author> Author3 </author>
		<isbn> isbn3 </isbn>
	</book>
</library>
 
// ***** aspx file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Import Namespace="System.Xml" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <table>
                <asp:Repeater runat="server" ID="repater1" DataSource='<%# doc.SelectNodes("/library/book") %>'>
                    <ItemTemplate>
                        <tr>
                            <td>
                                <%# (Container.DataItem as XmlNode)["title"].InnerText%>
                            </td>
                            <td>
                                <%# (Container.DataItem as XmlNode)["author"].InnerText%>
                            </td>
                            <td>
                                <%# (Container.DataItem as XmlNode)["isbn"].InnerText%>
                            </td>
                        </tr>
                    </ItemTemplate>
                    <FooterTemplate>
                        </div>
                    </FooterTemplate>
                </asp:Repeater>
            </table>
        </div>
    </form>
</body>
</html>
 
 
 
 
 
// **************
public partial class _Default : System.Web.UI.Page
{
  
    public System.Xml.XmlDocument doc;
    protected void Page_Load(object sender, EventArgs e)
    {
        string filePath = "XMLFile1.xml";
        doc = new System.Xml.XmlDocument();
        doc.Load(filePath);
        repater1.DataBind();
    }    
}

Open in new window

0
 

Author Comment

by:lrbrister
ID: 24386506
CodeCruiser
The data is coming back from a reote form post as XML
I can't write these to files...
I'm passing the data to a processing form as a Session("response") and then placing that as a dataset

I'll try what you placed there.
0
 

Author Comment

by:lrbrister
ID: 24386675
CodeCruiser
If you look at my XML Data above...you'll see that your reply is looking at the top tier...
How do I point it to other "levels"

Column 'referenceNumber' does not belong to table responseHeader.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentException: Column 'referenceNumber' does not belong to table responseHeader.

Source Error:
Line 222:        Dim dSet As New DataSet()
Line 223:        dSet = Session("response")
Line 224:        lblData.Text = dSet.Tables(0).Rows(0).Item("referenceNumber")
Line 225:

 
0
 

Author Closing Comment

by:lrbrister
ID: 31581508
Code Cruiser put me close to what I needed....channa_m: was helpful as well.

Final solution to access the child information was...
lblData.Text = dSet.Tables("ReservationToken").Rows(0).Item("referenceNumber").ToString
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

704 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